# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382891 | abil | Three Friends (BOI14_friends) | C++14 | 164 ms | 262148 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>
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
#define int long long
using namespace std;
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int inf = (1e9 + 7);
string p[N];
main(){
SPEEDUP;
int n;
cin >> n;
string s;
cin >> s;
if(!(n & 1)){
cout << "NOT POSSIBLE";
return 0;
}
string a = "", b = "";
for(int j = n / 2 + 1; j < n; j++){
b.pb(s[j]);
}
for(int i = n / 2; i >= 0; i--){
p[i] = a;
a = s[i] + a;
}
a = "";
vector<string > ans;
for(int i = 0;i <= n / 2; i++){
if(a + p[i] == b){
ans.pb(b);
}
a.pb(s[i]);
}
b = "";
a = "";
for(int i = 0;i < n / 2; i++){
a.pb(s[i]);
}
for(int i = n / 2; i < n; i++){
p[i] = b;
b.pb(s[i]);
}
b = "";
for(int i = n / 2; i < n; i++){
if(b + p[i] == a){
ans.pb(a);
}
b.pb(s[i]);
}
if(ans.size() > 1){
cout << "NOT UNIQUE";
return 0;
}
if(ans.empty()){
cout << "NOT POSSIBLE";
return 0;
}
cout << ans[0];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |