Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n;
- string s;
- cin>>n>>s;
- if(n%3 == 1)
- {
- cout<<"YES\n";
- continue;
- }
- if(n%3 == 2)
- {
- multiset<char> mst;
- for(int i=1; i<n; i+=3)
- mst.insert(s[i]);
- int f = 0;
- for(int i=0; i<n && f==0; i+=3)
- {
- if(mst.find(s[i]) != mst.end())
- f = 1;
- mst.erase(mst.find(s[i+1]));
- }
- if(f)
- cout<<"YES\n";
- else
- cout<<"NO\n";
- continue;
- }
- multiset<char> mst;
- for(int i=2; i<n; i+=3)
- mst.insert(s[i]);
- int f = 0;
- for(int i=0; i<n && f==0; i+=3)
- {
- if(mst.find(s[i]) != mst.end())
- f = 1;
- mst.erase(mst.find(s[i+2]));
- }
- if(f)
- cout<<"YES\n";
- else
- cout<<"NO\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment