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, q = 0, v = 0;
vector < int > vet;
cin >> n;
getchar();
string s, s11 = "", s12 = "",s21 = "", s22 = "", ante1 = "", ante2 = "", ante11 = "", ante22 = "";
cin >> s;
if(n%2 == 0) flag = 0;
else
{
for(int i = n-1; i >= 0 ; i--)
{
if(i <= n/2) s11.pb(s[i]);
else s21.pb(s[i]);
}
while(s11.size())
{
char k = s11[s11.size()-1];
s11.pop_back();
if(q)
{
ante2.pb(ante1[ante1.size()-1]);
ante1.pop_back();
}
if(s11 == s21 and s12 == s22)
{
if(!q)
{
ante1 = s11;
ante2 = s12;
q++;
flag = 1;
}
else if(ante1 == s11 and ante2 == s12 and flag == 1) flag = 1;
else flag = 2;
}
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 = n-1 ; i >= 0 ; i--)
{
if(i < n/2) s11.pb(s[i]);
else s21.pb(s[i]);
}
while(s21.size())
{
char k = s21[s21.size()-1];
s21.pop_back();
//cout << s21 << '*' << s22 << '*' << s11 << '*' << s12 << endl;
if(v)
{
ante22.pb(ante11[ante11.size()-1]);
ante11.pop_back();
}
if(s11 == s21 and s12 == s22)
{
if(!v)
{
ante11 = s21;
ante22 = s22;
v++;
flag = 1;
}
else if(ante11 == s21 and ante22 == s22 and flag == 1) flag = 1;
else flag = 2;
}
if(!s21.size()) continue;
s22.pb(k);
char k1 = s11[s11.size()-1];
s11.pop_back();
s12.pb(k1);
}
}
if(q)
{
while(ante1.size())
{
ante2.pb(ante1[ante1.size()-1]);
ante1.pop_back();
}
}
if(v)
{
while(ante11.size())
{
ante22.pb(ante11[ante11.size()-1]);
ante11.pop_back();
}
}
if(q and v and ante2 != ante22) flag = 2;
if(flag == 0) cout << "NOT POSSIBLE\n";
else
{
if(flag == 1)
{
if(q) cout << ante2 << endl;
else cout << ante22 << endl;
}
else cout << "NOT UNIQUE\n";
}
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:6:9: warning: unused variable 'cont' [-Wunused-variable]
int n, cont = -1, flag = 0, q = 0, v = 0;
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |