# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493987 | goodluck2020 | Three Friends (BOI14_friends) | C++14 | 59 ms | 15076 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 <bits/stdc++.h>
#define task "friends"
using namespace std;
const int N = 1e6 + 10;
int c, n, m, A[N], B[N], ans, res, tmp;
bool L[N], R[N];
string S;
void CALC()
{
L[0] = 1; R[n + 1] = 1;
for(int i = 1; i <= n; i++)
L[i] = min(L[i-1], (A[i] == B[i]));
for(int i = n; i >= 1; i--)
R[i] = min(R[i+1], (A[i] == B[i - 1]));
for(int i = 1; i < n; i++)
if(L[i-1] && R[i+1])
{
ans++;
res = tmp + i;
}
n = m = 0;
return;
}
void TruyVet(int k)
{
if(k > c/2)
for(int i = 0; i < c/2; i++) cout << S[i];
else
for(int i = c/2 + 1; i < c; i++) cout << S[i];
}
int main()
{
if(fopen(task ".inp","r"))
{
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> c >> S;
if(c % 2 == 0)
{
cout << "NOT POSSIBLE";
return 0;
}
for(int i = 0; i <= c/2; i++) A[++n] = S[i] - 'A';
for(int i = c/2 + 1; i < c; i++) B[++m] = S[i] - 'A';
CALC();
for(int i = 0; i < c/2; i++) B[++m] = S[i] - 'A';
for(int i = c/2; i < c; i++) A[++n] = S[i] - 'A';
tmp = c/2;
CALC();
if(ans == 1) TruyVet(res);
else if(ans > 1) cout << "NOT UNIQUE";
else cout << "NOT POSSIBLE";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |