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<cstdio>
#include<algorithm>
#include<string>
using namespace std;
#define N 2000001
int n, cnt;
string a, x, y;
void input()
{
char temp[N + 2];
scanf("%d", &n);
scanf("%s", temp);
a = temp;
a = "-" + a;
}
bool check(int s1, int e1, int s2, int e2)
{
int sig = 0;
for(int i = 0; i <= e1 - s1; i++)
{
//printf("------ %d %c %c\n", i, a[s1 + i], a[s2 + i + sig]);
if(a[s1 + i] != a[s2 + i + sig])
{
if(sig)
{
return false;
}
sig++;
}
}
return true;
}
void core()
{
if(n % 2 == 0)
{
printf("NOT POSSIBLE");
return;
}
if(check(1, n / 2, n / 2 + 1, n))
{
//printf("----------------------1\n");
x = '-';
for(int i = 1; i <= n / 2; i++)
{
x = x + a[i];
}
cnt++;
}
if(check(n / 2 + 2, n, 1, n / 2 + 1))
{
//printf("----------------------2\n");
y = '-';
for(int i = n / 2 + 2; i <= n; i++)
{
y = y + a[i];
}
cnt += 3;
}
//printf("-jsalkdak\n");
if(cnt == 0)
{
printf("NOT POSSIBLE");
}
else if(cnt % 2)
{
if(cnt == 1)
{
printf("%s", &x.c_str()[1]);
}
else
{
printf("%s", &y.c_str()[1]);
}
}
else
{
if(x == y)
{
printf("%s", &x.c_str()[1]);
}
else
{
printf("NOT UNIQUE");
}
}
//printf("%s\n", a.c_str());
//printf("%d", check(1, n / 2, n / 2 + 1, n));
}
int main()
{
input();
core();
return 0;
}
Compilation message (stderr)
friends.cpp: In function 'void input()':
friends.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
friends.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%s", temp);
| ~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |