# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
938418 | Ghulam_Junaid | Three Friends (BOI14_friends) | C++17 | 43 ms | 11804 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;
typedef long long ll;
ll k;
bool check(string s, string t){
int j = 0;
int i = 0;
int ind = t.size() - 1;
for (; i < s.size() and j < t.size();){
if (s[i] == t[j]){
i++;
j++;
}
else{
ind = j;
j++;
}
}
if (i == s.size())
return 1;
j = t.size() - 1;
i = s.size() - 1;
ind = 0;
for (; i >= 0 and j >= 0;){
if (s[i] == t[j]){
i--;
j--;
}
else{
ind = j;
j--;
}
}
if (i == -1)
return 1;
return 0;
}
int main(){
ll n;
string s;
cin >> n >> s;
n = s.size();
if (n % 2 == 0){
cout << "NOT POSSIBLE" << endl;
return 0;
}
k = n / 2;
string P, S;
for (ll i = 0; i < k; i ++)
P += s[i];
for (ll i = k + 1; i < n; i ++)
S += s[i];
if (P == S){
cout << P << endl;
return 0;
}
string ans;
string Q = s[k] + S;
int poss = check(P, Q);
if (poss)
ans = P;
int prev = poss;
Q = P + s[k];
poss += check(S, Q);
if (poss - prev)
ans = S;
if (poss > 1)
cout << "NOT UNIQUE" << endl;
else if (poss == 0)
cout << "NOT POSSIBLE" << endl;
else
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |