-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
55 lines (54 loc) · 1.07 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
int t,n,i,p;
string s;
cin>>t;
while(t--)
{
p=0;
cin>>n;
cin>>s;
map<string,int> mp;
if(n<=3)
{
cout<<"NO\n";
continue;
}
string x;
x.push_back(s[0]);
x.push_back(s[1]);
mp[x]++;
x.clear();
x.push_back(s[1]);
x.push_back(s[2]);
mp[x]++;
for(i=2;i<n-1;i++)
{
string y;
y.push_back(s[i]);
y.push_back(s[i+1]);
if(mp[y]>0)
{
if(s[i]==s[i-1] && s[i+1]==s[i] && mp[y]==1){
mp[y]++;
continue;
}
//cout<<y<<"\n";
p=1;
break;
}
else
mp[y]++;
}
if(p==0)
cout<<"NO\n";
else
cout<<"YES\n";
}
return 0;
}