# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
711805 | Karpin | Three Friends (BOI14_friends) | C++14 | 26 ms | 8008 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;
#define ll long long
#define vt vector
#define ar array
void solve(){
int n;
cin >> n;
string u;
cin >> u;
int numOfEachChar[30];
for (int i = 0; i < 30; i++){
numOfEachChar[i] = 0;
}
for (int i = 0; i < n; i++){
numOfEachChar[u[i] - 'A']++;
}
if (n % 2 == 0){
cout << "NOT POSSIBLE" << endl;
return;
}
bool torf = false;
int neededChar = -1;
for (int i = 0; i < 26; i++){
if (numOfEachChar[i] % 2 == 1){
if (torf){
cout << "NOT POSSIBLE" << endl;
return;
}
torf = true;
neededChar = i;
}
}
if (!torf){
cout << "NOT POSSIBLE" << endl;
return;
}
// vt<int> poses;
// for (int i = 0; i < n; i++){
// if (u[i] - 'A' == neededChar) poses.push_back(i);
// }
string res = "";
int plusOne = 0;
for (int i = 0; i <= n / 2; i++){
if (i == n / 2 && plusOne == 0) break;
if (u[i] != u[i + n / 2 + 1 - plusOne]) {
if (plusOne) {
res = "";
break;
}
plusOne++;
}else{
res += u[i];
}
}
plusOne = 0;
string res2 = "";
for (int i = 0; i <= n / 2; i++){
if (i == n / 2 && plusOne == 0) break;
if (u[i - plusOne] != u[i + n / 2]){
if (plusOne){
res2 = "";
break;
}
plusOne++;
}else{
res2 += u[i + n / 2];
}
}
if (res != "" && res2 != "") cout << "NOT UNIQUE" << endl;
else if (res == "" && res2 == "") cout << "NOT POSSIBLE" << endl;
else if (res != "") cout << res << endl;
else cout << res2 << endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int testcases = 1;
// cin >> testcases;
while(testcases--){
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |