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;
int n, len;
string s;
string r1, r2;
bool unico = true;
bool posible(int ini, int fin) {
int cont=0;
bool x = false;
while (cont < len) {
if (s[ini] != s[fin]) {
ini++;
x = true;
}
if (x && s[ini] != s[fin])
return false;
cont++;
ini++;
fin++;
}
return true;
}
int main() {
ios_base::sync_with_stdio();
cin.tie();
cin >> n >> s;
len = n/2;
string r1 = "", r2 = "";
if (posible(0, len+1))
r1 = s.substr(len+1, len);
if (posible(len, 0))
r2 = s.substr(0, len);
if ((r1.length() != len && r2.length() != len) || (n&1) == 0)
cout << "NOT POSSIBLE";
else if (r1.length() != len)
cout << r2;
else if (r2.length() != len)
cout << r1;
else if (r1 != r2)
cout << "NOT UNIQUE";
else
cout << r1;
return 0;
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:37:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | if ((r1.length() != len && r2.length() != len) || (n&1) == 0)
| ~~~~~~~~~~~~^~~~~~
friends.cpp:37:44: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | if ((r1.length() != len && r2.length() != len) || (n&1) == 0)
| ~~~~~~~~~~~~^~~~~~
friends.cpp:39:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
39 | else if (r1.length() != len)
| ~~~~~~~~~~~~^~~~~~
friends.cpp:41:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
41 | else if (r2.length() != len)
| ~~~~~~~~~~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |