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>
#define int long long
#define debug(x) if(0) cout << #x << " is " << x << "\n";
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
string S;
cin >> S;
if(N % 2 == 0){
cout << "NOT POSSIBLE";
return 0;
}
int X = (N - 1) / 2;
char curstr[N - 1];
char rightneow[X];
bool hvone = false;
int numcorrect = 0;
for(int i=1;i<N;i++){
curstr[i - 1] = S[i];
}
for(int i=0;i<X;i++){
if(curstr[i] == curstr[i + X]) numcorrect ++;
}
int numcorwithfunny = 0;
if(numcorrect == X && !hvone){
for(int j=0;j<X;j++) rightneow[j] = curstr[j];
for(int j=0;j<X;j++) if(rightneow[j] == curstr[j]) numcorwithfunny ++;
hvone = true;
}
for(int i=0;i<N - 1;i++){
//change curstr[i] to S[i]
if(i < X){
if(curstr[i] == curstr[i + X]){
if(S[i] != curstr[i + X]) numcorrect --;
}
else if(S[i] == curstr[i + X]) numcorrect ++;
}
else{
if(curstr[i] == curstr[i - X]){
if(S[i] != curstr[i - X]) numcorrect --;
}
else if(S[i] == curstr[i - X]) numcorrect ++;
}
if(hvone && i < X){
if(curstr[i] == rightneow[i]){
if(S[i] != rightneow[i]) numcorwithfunny --;
}
else if(S[i] == rightneow[i]) numcorwithfunny ++;
}
curstr[i] = S[i];
if(numcorrect == X && hvone){
debug(i);
debug(curstr[2]);
if(numcorwithfunny != X){
cout << "NOT UNIQUE";
return 0;
}
}
if(numcorrect == X && !hvone){
for(int j=0;j<X;j++) rightneow[j] = curstr[j];
for(int j=0;j<X;j++) if(rightneow[j] == curstr[j]) numcorwithfunny ++;
hvone = true;
}
}
if(hvone) for(int i=0;i<X;i++) cout << rightneow[i];
else cout << "NOT POSSIBLE";
}
Compilation message (stderr)
friends.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |