ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1102. Strange Dialog

Easy dp
Posted by Viktor Krivoshchekov`~ 10 May 2019 23:08
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <random>
#include <string>
#include <ctime>
#include <iostream>
#include <set>

using namespace std;

int main() {
int q;
cin >> q;
string s;
vector<bool> dp;
for(int _i = 0; _i < q; _i++){
cin >> s;
int n = s.size();
for (int _k = 0; _k < 6; _k++)
s += ' ';
dp.clear();
dp.resize(n + 10, false);
dp[n] = true;
for(int i = n - 2; i >= 0; i--){
if((s[i] == 'i' && s[i + 1] == 'n' && dp[i + 2])
|| (s[i] == 'o' && s[i + 1] == 'n' && s[i + 2] == 'e' && dp[i + 3])
|| (s[i] == 'o' && s[i + 1] == 'u' && s[i + 2] == 't' && dp[i + 3])
|| (s[i] == 'i' && s[i + 1] == 'n' && s[i + 2] == 'p' && s[i + 3] == 'u' && s[i + 4] == 't' && dp[i + 5])
|| (s[i] == 'p' && s[i + 1] == 'u' && s[i + 2] == 't' && s[i + 3] == 'o' && s[i + 4] == 'n' && dp[i + 5])
|| (s[i] == 'o' && s[i + 1] == 'u' && s[i + 2] == 't' && s[i + 3] == 'p' && s[i + 4] == 'u' && s[i + 5] == 't' && dp[i + 6])
)
dp[i] = true;
}
if(dp[0])
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}