-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCF1392D.cpp
More file actions
76 lines (70 loc) · 1.33 KB
/
CF1392D.cpp
File metadata and controls
76 lines (70 loc) · 1.33 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<bits/stdc++.h>
using namespace std;
#define ll int long long
#define mp make_pair
//#define for(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define N 1000000007
#define pq priority queue
#define pb push_back
#define pf push_front
#define mt make_tuple
#define prec(a) fixed<<setprecision(9)<<a
#define endl "\n"
#define fast_set s.max_load_factor(0.25);s.reserve(500);
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
const long double PI = (long double)(3.1415926535897932384626433832795);
int main()
{
fast;
int test,n,i,j,k;
cin>>test;
while(test--)
{
string str;
// input string consisiting of L and R.
cin>>n>>str;
int ans=0;
i=-1;
for(j=0;j<n-1;j++)
{
if(str[j]!=str[j+1])
{
i=j;
break;
}
}
if(i==-1)// if string consist of all L's or all R's.
{
ans=(n+2)/3;
}
else
{
int count=0;
j=(i+1)%n;;
int save=j;
do
{
if(str[j]!=str[(j-1+n)%n])
{
ans+=(count/3);
count=1;
}
else
{
count++;
}
j=(j+1)%n;
}
while(j!=save);
ans+=(count/3);
}
cout<<ans<<endl;
}
return 0;
}