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 <iomanip>
#include <fstream>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
int n;
string s, temp;
map<char, int> dict;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> s;
set<string> count;
for (int i = 0; i < n; i++) dict[s[i]]++;
for (int i = 0; i < n; i++) {
int one, two;
if (dict[s[i]] % 2 == 0) continue;
if (i == 0) {
one = 1;
two = n/2+1;
}
else if (i <= n/2) {
one = 0;
two = n/2 + 1;
}
else {
one = 0;
two = n/2;
}
//cout << "i: " << i << " one: " << one << " two: " << two << endl;
bool poss = true;
temp = "";
for (int j = 0; j < n/2; j++) {
if (s[one] != s[two]) {
poss = false;
break;
}
temp += s[one];
one++;
two++;
if (one == i) one++;
if (two == i) two++;
}
if (poss) count.insert(temp);
}
if (count.size() == 0) cout << "NOT POSSIBLE\n";
else if (count.size() == 1) cout << *(count.begin()) << endl;
else cout << "NOT UNIQUE\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |