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 <stdio.h>
#include <string.h>
#define N 2000001
int solve(char *aa, char *bb, int n) {
int i;
i = 0;
while (i < n && aa[i] == bb[i])
i++;
i++;
while (i <= n && aa[i] == bb[i - 1])
i++;
return i > n;
}
int main() {
static char cc[N + 1];
int n, pref, suff;
scanf("%d%s", &n, cc);
if (n % 2 == 0) {
printf("NOT POSSIBLE\n");
return 0;
}
pref = solve(cc + n / 2, cc, n / 2);
suff = solve(cc, cc + n / 2 + 1, n / 2);
if (!pref && !suff)
printf("NOT POSSIBLE\n");
else if (pref && suff)
printf("%s\n", strncmp(cc, cc + n / 2 + 1, n / 2) != 0 ? "NOT UNIQUE" : cc + n / 2 + 1);
else if (pref) {
cc[n / 2] = 0;
printf("%s\n", cc);
} else
printf("%s\n", cc + n / 2 + 1);
return 0;
}
Compilation message (stderr)
friends.c: In function 'main':
friends.c:22:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d%s", &n, cc);
| ^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |