-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1744C.cpp
More file actions
44 lines (38 loc) · 753 Bytes
/
1744C.cpp
File metadata and controls
44 lines (38 loc) · 753 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
int n;
char c;
string s;
ll ans = 0;
cin >> n >> c;
cin >> s;
if(c == 'g'){
cout<<0<<endl;
return;
}
else{
string t = s + s// sequence will repeat
ll last = -1;
for(int i = 2*n - 1 ; i >= 0 ; i--){
if(t[i] == 'g'){
last = i;
}
if(i < n && t[i] == c){
ans =max(ans , last - i);
}
}
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}