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;
#define int long long
main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
if (n % 2 == 0) {cout << "NOT POSSIBLE"; return 0;}
string s; cin >> s;
set<string> ans;
string ls = "", rs = "";
for (int x = 0; x < n/2; x++) ls.push_back(s[x]);
for (int x = n/2 + 1; x < n; x++) rs.push_back(s[x]);
if (ls == rs){
ans.insert(ls);
}
string lcomp = ls, rcomp = rs;
ls.push_back(s[n/2]);
rs = s[n/2] + rs;
bool lprepass[n]; memset(lprepass, 0, sizeof(lprepass));
bool lpostpass[n]; memset(lpostpass, 0, sizeof(lpostpass));
for (int x = 0; x < n/2; x++){
if (ls[x] == rcomp[x]){
lprepass[x] = 1;
}
else break;
}
for (int x = n/2+1; x > 0; x--){
if (ls[x] == rcomp[x-1]){
lpostpass[x] = 1;
}
else break;
}
if (lpostpass[1]) ans.insert(rcomp);
for (int x = 0; x < n/2; x++){
if (lprepass[x] && lpostpass[x+2]){
ans.insert(rcomp);
break;
}
}
if (lprepass[n/2 - 1]) ans.insert(rcomp);
bool rprepass[n]; memset(rprepass, 0, sizeof(rprepass));
bool rpostpass[n]; memset(rpostpass, 0, sizeof(rpostpass));
for (int x = 0; x < n/2; x++){
if (rs[x] == lcomp[x]){
rprepass[x] = 1;
}
else break;
}
for (int x = n/2+1; x > 0; x--){
if (rs[x] == lcomp[x-1]){
rpostpass[x] = 1;
}
else break;
}
if (rpostpass[1]) ans.insert(lcomp);
for (int x = 0; x < n/2; x++){
if (rprepass[x] && rpostpass[x+2]){
ans.insert(lcomp);
break;
}
}
if (rprepass[n/2 - 1]) ans.insert(lcomp);
if (ans.size() == 0) cout << "NOT POSSIBLE";
else if (ans.size() == 1) cout << *ans.begin();
else cout << "NOT UNIQUE";
}
Compilation message (stderr)
friends.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |