# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38479 | Waschbar | Three Friends (BOI14_friends) | C++14 | 76 ms | 7860 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>
using namespace std;
int cnt[100];
int main() {
string s;
int n;
cin >> n;
cin >> s;
if(n%2 == 0) {
cout << "NOT POSSIBLE";
return 0;
}
for(int i = 0; i < n; i++)
cnt[s[i]-'A']++;
char ch;
int tmp = 0;
for(int i = 0; i < 30; i++)
if(cnt[i]%2) tmp++,ch = (char)('A'+i);
if(tmp != 1) {
cout << "NOT POSSIBLE";
return 0;
}
int x1, x2, y1, y2;
bool ind = 0;
x1 = n/2; x2 = n-1;
y1 = y2 = -1;
while(x1 >= 0 && x2 > n/2) {
if(s[x1] != s[x2] && s[x1] == ch){
y1 = x1;
if((x1 > 0 && s[x1-1] == ch) || (x1 < n/2 && s[x1+1] == ch)) ind = 1;
break;
}
x1--; x2--;
}
if(x1 >= 0 && x2 <= n/2 && s[x1] == ch){
y1 = x1;
if((x1 > 0 && s[x1-1] == ch) || (x1 < n/2 && s[x1+1] == ch)) ind = 1;
}
x1 = n/2-1; x2 = n-1;
while(x1 >= 0 && x2 >= n/2) {
if(s[x1] != s[x2] && s[x2] == ch){
y2 = x2;
if((x2 > n/2 && s[x2-1] == ch) || (x2 < n-1 && s[x2+1] == ch)) ind = 1;
break;
}
x1--; x2--;
}
if(x1 > 0 && x2 <= n/2 && s[x2] == ch){
y2 = x2;
if((x2 > n/2 && s[x2-1] == ch) || (x2 < n-1 && s[x2+1] == ch)) ind = 1;
}
// cout << y1 << " " << y2 << " " << ch << endl;
if(y1 == -1 && y2 == -1) {
cout << "NOT POSSIBLE";
return 0;
}
if(y1 != -1) {
x1 = 0; x2 = n/2+1;
if(x1 == y1) x1++;
while(x1 <= n/2) {
if(s[x1] != s[x2]) {
cout << "NOT POSSIBLE";
return 0;
}
x1++; x2++;
if(x1 == y1) x1++;
}
}
else {
x1 = 0; x2 = n/2;
if(x2 == y2) x2++;
while(x1 < n/2) {
if(s[x1] != s[x2]) {
cout << "NOT POSSIBLE";
return 0;
}
x1++; x2++;
if(x2 == y2) x2++;
}
}
if(y1 != y2 && y1 != -1 && y2 != -1) ind = 1;
if(ind){
cout <<"NOT UNIQUE";
return 0;
}
if(y1 != -1) {
x1 = 0; x2 = n/2+1;
if(x1 == y1) x1++;
while(x1 <= n/2) {
cout << s[x1];
x1++; x2++;
if(x1 == y1) x1++;
}
}
else {
x1 = 0; x2 = n/2;
if(x2 == y2) x2++;
while(x1 < n/2) {
cout << s[x2];
x1++; x2++;
if(x2 == y2) x2++;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |