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 endl '\n'
#define MOD 1e9 + 7
int n,a[26];
string s,ans = "-";
bool solve(string p,string t)
{
string tmp;
tmp = t.substr(1,t.length()-1);
if(p==tmp){ ans = p; return true; }
tmp = t.substr(0,t.length()-1);
if(p==tmp){ ans = p; return true; }
int lp = 0,lt = 0,l = 0;
while(true)
{
if(p[lp]==t[lt]) l++;
else break;
lp++; lt++;
if(lp>=p.length() or lt>=t.length()) break;
}
int rp = p.length()-1,rt = t.length()-1,r = 0;
while(true)
{
if(p[rp]==t[rt]) r++;
else break;
rp--; rt--;
if(rp<0 or rt<0) break;
}
if(l+r>=p.length()){ ans = p; return true; }
else return false;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> s;
if(n%2==0){ cout << "NOT POSSIBLE"; return 0; }
for(int i = 0;i < n;i++) a[s[i]-'A']++;
int cnt = 0;
for(int i = 0;i < 26;i++) if(a[i]%2==1){ cnt++; if(cnt>1){ cout << "NOT POSSIBLE"; return 0; }}
string a = s.substr(0,n/2);
string b = a+s[n/2];
string c = s.substr(n/2+1,n/2);
string d = s[n/2]+c;
bool x = solve(a,d),y = solve(c,b);
if(x and y){ cout << "NOT UNIQUE"; return 0; }
else if(ans=="-"){ cout << "NOT POSSIBLE"; return 0; }
else cout << ans;
}
Compilation message (stderr)
friends.cpp: In function 'bool solve(std::__cxx11::string, std::__cxx11::string)':
friends.cpp:22:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(lp>=p.length() or lt>=t.length()) break;
~~^~~~~~~~~~~~
friends.cpp:22:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(lp>=p.length() or lt>=t.length()) break;
~~^~~~~~~~~~~~
friends.cpp:32:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(l+r>=p.length()){ ans = p; return true; }
~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |