-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServal_And_Inversion_Magic.cpp
60 lines (53 loc) · 1.22 KB
/
Serval_And_Inversion_Magic.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
56
57
58
59
60
// serval; and mocha's arrAY
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define dl double long
#define pb(x) push_back(x)
// #define forall(i,n) for(int i=0;i<n;i++)
// #define for(i,n) for(int i=1;i<n;i++)
// #define foreach(x,arr) for(auto x: arr)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(NULL);
signed main(){
fast;
int ts; cin>>ts;
while(ts--){
int n; cin>>n;
string s,rev_s; cin>>s;
rev_s=s;
reverse(rev_s.begin(), rev_s.end());
if(rev_s==s) cout<<"YES\n";
else{
int start=0,end=n-1;
while(start<=end){
if(s[start]==s[end]){
start++; end--;
}else break;
}
while(start<=end){
if(s[start]!=s[end]){
s[start]=s[end]; start++; end--;
}else break;
}
rev_s=s;
reverse(rev_s.begin(), rev_s.end());
if(s==rev_s)cout<<"YES\n";
else cout<<"NO\n";
}
}
}
/*
6
2
3 6
3
1 2 4
3
3 6 1
3
15 35 21
4
35 10 35 14
5
1261 227821 143 4171 1941
*/