# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112251 | lucascgar | Three Friends (BOI14_friends) | C++17 | 23 ms | 8364 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;
/*
resposta ta na metade esquerda ou na metade direita
*/
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int MAXN = 2e6+11;
int q[27]; // A = 0
bool check(string &c, string &o){
// cerr << c << ' ' << o << '\n';
bool s = 0;
int j = 0;
for (int i=0;i<c.size();i++){
char x = c[i];
if (o[j] == x){
j++;
continue;
}
if (s) return 0;
s=1, j++, i--;
}
return 1;
}
signed main(){
std::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
for (auto &x:s) q[x-'A']++;
int qo = 0, tg;
for (int i=0;i<26;i++) if (q[i]%2==1){
qo++, tg=i;
}
if (s.size()%2 == 0 || qo>1){
cout << "NOT POSSIBLE\n";
return 0;
}
set<string> fans;
int sz = n/2;
string st, o;
for (int i=0;i<sz;i++){
st.push_back(s[i]);
}
for (int i=sz;i<n;i++) o.push_back(s[i]);
if (check(st, o)) fans.insert(st);
st.clear();
o.clear();
for (int i=0;i<=sz;i++) o.push_back(s[i]);
for (int i=sz+1;i<n;i++) st.push_back(s[i]);
if (check(st, o)) fans.insert(st);
if (fans.empty()){
cout << "NOT POSSIBLE\n";
}else if (fans.size()>1){
cout << "NOT UNIQUE\n";
}else{
cout << *fans.begin() << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |