[contest:https://mirror.codeforces.com/contest/2178]↵
Key Observation: ↵
==================↵
↵
1.The "Yes" is Persistent: In the rules, **_Y OR N = Y_**. This means a Y never disappears; it just "**eats**" the N next to it.↵
2.The Trap: If you have two Ys, they will eventually have to meet as the string gets shorter. Because a Y cannot be turned back into an N, those two Ys will eventually be forced to merge.↵
3.The Rule: If the string has 0 or 1 Y, you can always merge all N's together first, then merge that single N with the single Y. But if there are greater than equal (>=) 2 Ys, you will eventually be forced to break the rule.↵
↵
Implementation: ↵
==================↵
↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
int main()↵
{↵
ios::sync_with_stdio(false);↵
cin.tie(NULL);↵
int test;nt test; ↵
cin >> test;↵
↵
while (test--)↵
{↵
string s;↵
cin >> s;↵
↵
int Ycount = 0;↵
for (char c : s)↵
{↵
if (c == 'Y')↵
Ycount++;↵
}↵
↵
if (Ycount > 1) cout << "NO" << "\n";↵
↵
else cout << "YES" << "\n"; ↵
}↵
↵
return 0;↵
}
Key Observation: ↵
1.The "Yes" is Persistent: In the rules, **_Y OR N = Y_**. This means a Y never disappears; it just "**eats**" the N next to it.↵
2.The Trap: If you have two Ys, they will eventually have to meet as the string gets shorter. Because a Y cannot be turned back into an N, those two Ys will eventually be forced to merge.↵
3.The Rule: If the string has 0 or 1 Y, you can always merge all N's together first, then merge that single N with the single Y.
↵
Implementation: ↵
↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
int main()↵
{↵
i
cin.tie(NULL);↵
int test;
cin >> test;↵
↵
while (test--)↵
{↵
string s;↵
cin >> s;↵
↵
int Ycount = 0;↵
for (char c : s)↵
{↵
if (c == 'Y')↵
Ycount++;↵
}↵
↵
if (Ycount > 1) cout << "NO" << "\n";↵
↵
else cout << "YES" << "\n"; ↵
}↵
↵
return 0;↵
}




