# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
938399 | Ghulam_Junaid | Three Friends (BOI14_friends) | C++17 | 42 ms | 13632 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;
const ll mod = 1e9 + 7;
const ll base = 727;
ll k;
set<int> st;
void check(string s, string t, bool is_suff){
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())
st.insert(ind + k * is_suff);
j = t.size() - 1;
ind = 0;
for (int i = s.size() - 1; i >= 0 and j >= 0;){
if (s[i] == t[j]){
i--;
j--;
}
else{
ind = j;
j--;
}
}
if (i == -1)
st.insert(ind + k * is_suff);
}
int main(){
ll n;
string s;
cin >> n >> s;
if (n % 2 == 0){
cout << "NOT POSSIBLE" << endl;
return 0;
}
k = n / 2;
ll poss = 0;
string P, S;
for (ll i = 0; i < k; i ++)
P += s[i];
for (ll i = k + 1; i < n; i ++)
S += s[i];
string ans;
string Q = s[k] + S;
check(P, Q, 1);
if (st.size())
ans = P;
int prev = st.size();
Q = P + s[k];
check(S, Q, 0);
if (st.size() - prev)
ans = S;
if (st.size() > 1)
cout << "NOT UNIQUE" << endl;
else if (st.size() == 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... |