# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243826 | kimbj0709 | Three Friends (BOI14_friends) | C++14 | 67 ms | 20004 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 int long long
#define mod 1000000009
#define po 191
#define maxn 2000050
vector<int> powers(maxn,1);
int len;
string find(string input){
string ret = "";
int can1 = 0;
int currsum = 0;
int target = 0;
for(int i=1;i<len/2+1;i++){
currsum += (input.at(i)-'A')*powers[i-1];
currsum %= mod;
}
for(int i=len/2+1;i<len;i++){
target += (input.at(i)-'A')*powers[i-len/2-1];
target %= mod;
}
if(currsum==target){
can1++;
}
for(int i=0;i<len/2;i++){
currsum -= (input.at(i+1)-'A')*powers[i];
currsum += (input.at(i)-'A')*powers[i];
currsum += mod*2;
currsum %= mod;
if(currsum==target){
can1++;
}
}
if(can1>0){
for(int j=input.length()-1;j>input.length()-1-input.length()/2;j--){
ret += input.at(j);
}
reverse(ret.begin(),ret.end());
}
return ret;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string input;
cin >> len >> input;
if(len%2==0){
cout << "NOT POSSIBLE";
return 0;
}
for(int i=1;i<powers.size();i++){
powers[i] = powers[i-1]*po;
powers[i] %= mod;
}
string temp1 = find(input);
reverse(input.begin(),input.end());
string temp2 = find(input);
reverse(temp2.begin(),temp2.end());
if(temp1.length()==0&&temp2.length()==0){
cout << "NOT POSSIBLE";
}
else if(temp1.length()==0&&temp2.length()!=0){
cout << temp2;
}
else if(temp1.length()!=0&&temp2.length()==0){
cout << temp1;
}
else if(temp1!=temp2){
cout << "NOT UNIQUE";
}
else{
cout << temp1;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |