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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pff pair<float, float>
#define coutpair(p) cout << p.first << " " << p.second << "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
string s; cin >> s;
if (n%2==0 || n < 3){
cout << "NOT POSSIBLE";
return 0;
}
set<string> st;
string s1, s2;
int mid = n/2;
for (int i=mid+1; i<n; i++) s1 += s[i];
int p1, p2;
for(p1=0; p1<mid; p1++){
if (s[p1] != s1[p1]) break;
}
for(p2=mid; p2>0; p2--){
if (s[p2] != s1[p2-1]) break;
}
if (p1 >= p2) st.insert(s1);
for (int i=0; i<mid; i++) s2 += s[i];
for (p1=mid; p1<n-1; p1++){
if (s[p1] != s2[p1-mid]) break;
}
for(p2=n-1; p2>mid; p2--){
if (s[p2] != s2[p2-1-mid]) break;
}
if (p1 >= p2) st.insert(s2);
if (st.size() > 1) cout << "NOT UNIQUE";
else if (st.size() == 1) cout << *st.begin();
else cout << "NOT POSSIBLE";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |