# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548630 | Amylopectin | Three Friends (BOI14_friends) | C++14 | 63 ms | 4704 KiB |
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 <iostream>
#include <stdio.h>
using namespace std;
const int mxn = 2e6 + 10;
char s[mxn] = {};
int let[31] = {};
int main()
{
int i,j,n,m,odd,cou = 0,cl,cr,ans[2] = {},of;
scanf("%d %s",&n,&s);
for(i=0; i<n; i++)
{
let[s[i] - 'A'] ++;
}
for(i=0; i<26; i++)
{
if(let[i] % 2 == 1)
{
cou ++;
odd = i;
}
}
if(cou != 1 || n % 2 == 0)
{
printf("NOT POSSIBLE\n");
return 0;
}
cl = 0;
cr = n/2;
for(j=0; j<2; j++)
{
if(j == 1)
{
cl = 0;
cr = n/2 + 1;
}
of = 0;
for(i=0; i<n/2; i++)
{
if(s[cl] != s[cr])
{
of ++;
if(of > 1)
{
break;
}
if(j == 0)
{
// if(s[cr] - 'A' != odd)
// {
// of = 2;
// break;
// }
cr ++;
}
else
{
// if(s[cl] - 'A' != odd)
// {
// of = 2;
// break;
// }
cl ++;
}
i--;
}
else
{
cl ++;
cr ++;
}
}
if(of >= 2)
{
ans[j] = -1;
}
else
ans[j] = 1;
}
if(ans[0] == 1)
{
if(ans[1] == 1)
{
of = 0;
for(i=0; i<n/2; i++)
{
if(s[i] != s[i+n/2+1])
{
of = 1;
break;
}
}
if(of == 1)
printf("NOT UNIQUE\n");
else
{
for(i=0; i<n/2; i++)
{
printf("%c",s[i]);
}
printf("\n");
}
}
else
{
for(i=0; i<n/2; i++)
{
printf("%c",s[i]);
}
printf("\n");
}
}
else
{
if(ans[1] == 1)
{
for(i=n/2+1; i<n; i++)
{
printf("%c",s[i]);
}
printf("\n");
}
else
{
printf("NOT POSSIBLE\n");
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |