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;
const int maxn=2000010;
int n_, n;
char str[maxn], s1[maxn], s2[maxn], s3[maxn], s4[maxn];
int mini;
int verif(char str1[maxn], char str2[maxn]){
for(int i=0; i<=n; i++){
if(str1[i]!=str2[i]){
mini=i;
break;
}
}
// printf("mini=%d\n", mini);
int cont=0, da=1;
for(int i=0; i<n; i++){
if(cont==mini) cont++;
// printf("%c %c\n", str1[i], str2[cont]);
if(str1[i]!=str2[cont]) da=0;
cont++;
}
// printf("%d\n", da);
if(da==0) return 0;
if( (str2[mini]==str2[mini-1] && mini>=1) || (str2[mini]==str2[mini+1] && mini<=n-1) ) return 2;
return 1;
}
int main(){
scanf("%d", &n_);
scanf(" %s ", &str);
if(n_%2==0){
printf("NOT POSSIBLE\n");
return 0;
}
n=n_/2;
for(int i=0; i<n; i++) s1[i]=str[i];
for(int i=n; i<=2*n; i++) s2[i-n]=str[i];
for(int i=n+1; i<=2*n; i++) s3[i-n-1]=str[i];
for(int i=0; i<=n; i++) s4[i]=str[i];
int x=verif(s1, s2);
int mini1=mini;
int y=verif(s3, s4);
int mini2=mini;
// printf("%s %s %s %s\n", s1, s2, s3, s4);
if(x+y==0) printf("NOT POSSIBLE\n");
if(x+y==1){
if(x==1) printf("%s\n", s1);
else printf("%s\n", s3);
}
if(x+y>=2){
// printf("%d %d %d %d\n", x, y, mini1, mini2);
if(x==1 && y==1 && mini1==0 && mini2==3) printf("%s\n", s1);
else printf("NOT UNIQUE\n");
}
return 0;
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:32:20: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[2000010]' [-Wformat=]
scanf(" %s ", &str);
~~~~^
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 ", &str);
~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |