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 n;
string s;
set<string> st;
// search for [l2,r2] in [l1,r1] with exactly one mismatch and skip it
bool match_and_skip(int l1, int r1, int l2, int r2) {
int cnt = 0;
string ret = "";
while(l1 <= r1 && l2 <= r2) {
if(s[l1] != s[l2]) cnt++, l2--;
else ret += s[l1];
if(cnt > 1) return false;
l1++, l2++;
}
if(cnt == 1 || (l1 <= r1 && cnt == 0)) st.insert(ret);
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> s;
if(~n&1) { cout << "NOT POSSIBLE\n"; return 0; }
int len = n>>1;
match_and_skip(0,len,len+1,n-1); // (.x..)(...)
match_and_skip(len,n-1,0,len-1); // (...)(..x.)
if(st.size() == 0) cout << "NOT POSSIBLE\n";
else if(st.size() > 1) cout << "NOT UNIQUE\n";
else cout << *(st.begin()) << "\n";
return 0;
}
Compilation message (stderr)
friends.cpp: In function 'bool match_and_skip(int, int, int, int)':
friends.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |