# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105809 | xiaowuc1 | Three Friends (BOI14_friends) | C++14 | 24 ms | 7452 KiB |
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 <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;
bool can(string a, string b) {
int aIdx = 0;
for(int i = 0; i < b.size() && aIdx < a.size(); i++) {
if(b[i] == a[aIdx]) aIdx++;
}
return aIdx == a.size();
}
void solve() {
int n;
string s;
cin >> n >> s;
if(n%2==0) {
cout << "NOT POSSIBLE\n";
return;
}
n /= 2;
set<string> ret;
if(can(s.substr(0, n), s.substr(n))) {
ret.insert(s.substr(0, n));
}
if(can(s.substr(n+1), s.substr(0, n+1))) {
ret.insert(s.substr(n+1));
}
if(ret.size() > 1) cout << "NOT UNIQUE\n";
else if(ret.empty()) cout << "NOT POSSIBLE\n";
else cout << *ret.begin() << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
/*
int t;
cin >> t;
for(int i = 1; i <= t; i++) {
cout << "Case #" << i << ": ";
solve();
}
*/
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |