Ankit_132

3-Blast Palindrome

Jul 12th, 2023
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n;
  14.         string s;
  15.         cin>>n>>s;
  16.  
  17.         if(n%3 == 1)
  18.         {
  19.             cout<<"YES\n";
  20.             continue;
  21.         }
  22.  
  23.         if(n%3 == 2)
  24.         {
  25.             multiset<char> mst;
  26.             for(int i=1; i<n; i+=3)
  27.                 mst.insert(s[i]);
  28.  
  29.             int f = 0;
  30.  
  31.             for(int i=0; i<n && f==0; i+=3)
  32.             {
  33.                 if(mst.find(s[i]) != mst.end())
  34.                     f = 1;
  35.  
  36.                 mst.erase(mst.find(s[i+1]));
  37.             }
  38.  
  39.             if(f)
  40.                 cout<<"YES\n";
  41.             else
  42.                 cout<<"NO\n";
  43.  
  44.             continue;
  45.         }
  46.  
  47.  
  48.         multiset<char> mst;
  49.         for(int i=2; i<n; i+=3)
  50.             mst.insert(s[i]);
  51.  
  52.         int f = 0;
  53.  
  54.         for(int i=0; i<n && f==0; i+=3)
  55.         {
  56.             if(mst.find(s[i]) != mst.end())
  57.                 f = 1;
  58.  
  59.             mst.erase(mst.find(s[i+2]));
  60.         }
  61.  
  62.         if(f)
  63.             cout<<"YES\n";
  64.         else
  65.             cout<<"NO\n";
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment