이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
string s;
bool check(string t, int l, int r) {
int pos = 0;
for(int i = l; i <= r; i++) {
if(pos != t.size() && t[pos] == s[i]) {
pos++;
}
}
return (pos == t.size());
}
void Solve() {
int n;
cin >> n;
cin >> s;
if(n % 2 == 0) {
cout << "NOT POSSIBLE\n";
return;
}
bool f1 = check(s.substr(0, n / 2), n / 2, n - 1), f2 = check(s.substr(n - n / 2, n / 2), 0, n / 2);
if(!f1 && !f2) {
cout << "NOT POSSIBLE\n";
}
else if(f1 && f2 && s.substr(0, n / 2) != s.substr(n - n / 2, n / 2)) {
cout << "NOT UNIQUE\n";
}
else if(f1) {
cout << s.substr(0, n / 2) << "\n";
}
else {
cout << s.substr(n - n / 2, n / 2) << "\n";
}
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp: In function 'bool check(std::string, long long int, long long int)':
friends.cpp:12:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | if(pos != t.size() && t[pos] == s[i]) {
| ~~~~^~~~~~~~~~~
friends.cpp:16:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | return (pos == t.size());
| ~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |