This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << " - " << #x << ": " << x << '\n';
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << '\n';
#define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << " ,"; cerr << ']' << "\n";
string ss;
int n ;
bool binary_s(int deb, int end , int len){
string one = ss.substr(deb , len);
string two = ss.substr(end-(len-1),len);
return one == two;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt;
cin >> tt;
while(tt--){
cin >> ss;
n = ss.length();
map<char , vector<int>> mp;
for(int i = 0 ; i < n ; i++){
mp[ss[i]].push_back(i);
}
for(map<char, vector<int>>::iterator it = mp.begin();it!=mp.end() ; it++){
reverse(it->second.begin(),it->second.end());
}
int ans = 1;
for(int i = n-1,qs = 0 ; qs < n/2 ; i--, qs++){
map<int,bool>new_a;
vector<int>test;
for(int j = 0 ; j < (int)mp[ss[i]].size() ; j++){
new_a[mp[ss[i]][j]-qs] = 1;
test.push_back(mp[ss[i]][j]-qs);
}
vector<int>v = mp[ss[qs]];
bool is = 1;
for(int j = 0 ; j < (int)mp[ss[qs]].size() ; j++){
if(v[j]<n/2 || v[j]>i)continue;
if(new_a[i-v[j]]){
if(binary_s(qs , i , i-v[j]+1)){
int len = i-v[j];
qs+=len;
i-=len;
ans += 2;
is = 0;
if(qs+1==i)ans--;
break;
}
}
}
if(is)break;
}
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |