-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenta Game.cpp
More file actions
76 lines (75 loc) · 1.78 KB
/
Genta Game.cpp
File metadata and controls
76 lines (75 loc) · 1.78 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>
#define ll long long
#define pii pair<int,int>
#define sf(a) scanf("%d",&a)
#define pf(a) printf("%d\n",a)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define F first
#define S second
#define Check cout<< "Done in " << clock() / CLOCKS_PER_SEC <<" sec"<< endl;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int v;
void isPalindrome(string s)
{
int len = s.size();
for(int i=0;i<len/2;i++)
{
if(s[i] != s[len-i-1])
v++;
}
}
int main()
{
FastRead
int t;
cin >> t;
while(t--)
{
ll n,m,cnt=0;
v = 0;
cin >> n >> m;
string s;
cin >> s;
int idx;
char c;
isPalindrome(s);
int len = s.size();
int cr = -1;
if(len&1)
cr = len/2;
for(int i=1;i<=m;i++)
{
cin >> idx >> c;
int xx = len/2;
if(idx-1 == cr)
{
}
else
{
if(!v)
{
if(s[idx-1] != c)
v++;
}
else
{
if(s[idx-1] != s[len-idx])
{
if(s[len-idx] == c)
v--;
}
else if(s[idx-1] != c)
v++;
}
s[idx-1] = c;
}
if(v == 0)
cnt++;
}
cout << cnt << endl;
}
}