My issue
Please can anyone help me, why my solution doesn’t work? The intution idea is similar to the idea of the author’s solution, but I have implemented it differently.
My code
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll t,n,i,j,k;
cin >> t;
while(t--)
{
cin >> n;
string s1;
cin >> s1;
if(n%3==1)
{
cout << "YES\n";
continue;
}
map<char,pair<ll,ll>>m1;
for(auto x:s1)
{
m1[x]=make_pair(0ll,0ll);
}
if(n%3==0)
{
for(i=0;i<n;i++)
{
if((i+1)%3==1)
m1[s1[i]].first=1ll;
else if((i+1)%3==0)
m1[s1[i]].second=1ll;
}
}
else
{
for(i=0;i<n;i++)
{
if((i+1)%3==1)
m1[s1[i]].first=1ll;
else if((i+1)%3==2)
m1[s1[i]].second=1ll;
}
}
ll f=0ll;
for(auto x:m1)
{
// cout << x.first << "->" << x.second.first << ", "<< x.second.second << "\n";
if(((x.second).first==1) && ((x.second).second==1))
{
f=1ll;
// cout << x.first<< " ";
break;
}
}
if(f==1ll)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
Problem Link: BLAST3 Problem - CodeChef