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;
typedef long long ll;
const int MAXN=2e6+6;
const int MOD=1e9+9;
const int P=257;
char v[MAXN];
ll h[MAXN], pot[MAXN];
int n;
int gh(int ini, int fim) {
if(fim<ini) return 0;
ll val=h[ini-1]*pot[fim-ini+1];
val%=MOD;
val=h[fim]-val; val%=MOD;
val+=MOD; val%=MOD;
return val;
}
ll junta(ll a, ll b, int tam) {
if(tam==0) return b;
if(tam==n/2) return a;
tam=(n/2)-tam;
ll val=a*pot[tam];
val+=b;
return val;
}
int main() {
scanf("%d", &n);
scanf(" %s", &v[1]);
if(n%2==0) {
printf("NOT POSSIBLE\n");
return 0;
}
pot[0]=1;
for(int i=1; i<=n; i++) {
h[i]=h[i-1]*P;
h[i]+=v[i];
h[i]%=MOD;
pot[i]=pot[i-1]*P;
pot[i]%=MOD;
}
// for(int i=1; i<=n; i++) printf("%d ", pot[i]); printf("\n");
// printf("ghs %lld e %lld\n", gh(2, 5), gh(4, 7));
int resp=-1;
for(int i=1; i<=n; i++) {
ll aa, bb;
// printf("testando %d\n", i);
if(i<=(n+1)/2) {
aa=junta( gh(1, i-1), gh(i+1, (n+1)/2), i-1 );
bb=gh((n+1)/2+1, n);
// printf("[%d %d] [%d %d] (%d) // [%d %d] >> ", 1, i-1, i+1, (n+1)/2, i-1, (n+1)/2+1, n);
// printf("%lld %lld\n", aa, bb);
}
else {
aa=gh(1, n/2);
bb=junta( gh((n+1)/2, i-1) , gh(i+1, n), i-(n+1)/2 );
// printf("[%d %d] // [%d %d] [%d %d] (%d) >> ", 1, n/2, (n+1)/2, i-1, i+1, n, i-(n+1)/2);
// printf("%lld %lld\n", aa, bb);
}
if(aa==bb) {
// printf("ok %d\n", i);
if(resp!=-1) {
printf("NOT UNIQUE\n");
return 0;
}
resp=i;
}
}
if(resp==-1) {
printf("NOT POSSIBLE\n");
return 0;
}
if(resp<=(n+1)/2) {
for(int i=1; i<=(n+1)/2; i++) if(i!=resp) printf("%c", v[i]);
}
else {
for(int i=n/2; i<=n; i++) if(i!=resp) printf("%c", v[i]);
}
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
friends.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s", &v[1]);
~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |