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>
#define pb push_back
using namespace std;
int main()
{
int n, cont = -1, flag = 0;
vector < int > vet;
cin >> n;
getchar();
string s, s11 = "", s12 = "",s21 = "", s22 = "";
cin >> s;
if(n%2 == 0) flag = 0;
else
{
for(int i = 0 ; i < n ; i++)
{
if(i <= n/2) s11.pb(s[i]);
else s21.pb(s[i]);
}
reverse(s11.begin(), s11.end());
reverse(s21.begin(), s21.end());
while(s11.size())
{
char k = s11[s11.size()-1];
s11.pop_back();
if(s11 == s21 and s12 == s22)
{
vet.pb((n/2 - s11.size()));
flag = 1;
}
if(!s11.size()) continue;
s12.pb(k);
char k1 = s21[s21.size()-1];
s21.pop_back();
s22.pb(k1);
}
s11 = "", s12 = "",s21 = "", s22 = "";
for(int i = 0 ; i < n ; i++)
{
if(i < n/2) s11.pb(s[i]);
else s21.pb(s[i]);
}
reverse(s11.begin(), s11.end());
reverse(s21.begin(), s21.end());
while(s21.size())
{
char k = s21[s21.size()-1];
s21.pop_back();
if(s11 == s21 and s12 == s22)
{
vet.pb((n - 1 - s21.size()));
flag = 1;
}
if(!s21.size()) continue;
s22.pb(k);
char k1 = s11[s11.size()-1];
s11.pop_back();
s12.pb(k1);
}
}
if(flag == 0) cout << "NOT POSSIBLE\n";
else
{
sort(vet.begin(), vet.end());
string r1 = "", r2 = "", ante1 = "", ante2 = "";
for(int i = 0 ; i < vet[0] ; i++) r1.pb(s[i]), ante1.pb(s[i]);
for(int i = vet[0]+1 , j = r1.size(); j < n/2 ; j++, i++) r2.pb(s[i]), ante2.pb(s[i]);
reverse(r2.begin(), r2.end());
reverse(ante2.begin(), ante2.end());
for(int i = 1 ; i < vet.size() ; i++)
{
if(vet[i-1] != vet[i] and vet[i-1] < n/2) r1.pb(vet[i-1]);
for(int j = vet[i-1]+1 ; j < vet[i] and ante2.size(); j++)
{
r1.pb(s[j]);
ante1.pb(s[j]);
r2.pop_back();
ante2.pop_back();
}
if(ante2.size() != 0) ante2.pop_back();
if(r1 == ante1 and r2 == ante2) flag = 1;
else
{
flag = 2;
break;
}
}
if(flag == 1)
{
cout << ante1;
reverse(ante2.begin(), ante2.end());
cout << ante2 << endl;
}
else cout << "NOT UNIQUE\n";
}
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:72:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1 ; i < vet.size() ; i++)
~~^~~~~~~~~~~~
friends.cpp:6:13: warning: unused variable 'cont' [-Wunused-variable]
int n, cont = -1, flag = 0;
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |