Submission #1300634

#TimeUsernameProblemLanguageResultExecution timeMemory
1300634kirakosyanThree Friends (BOI14_friends)C++20
100 / 100
12 ms10228 KiB
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<set> #include<map> #include<queue> #include<stack> #include<unordered_map> #include<unordered_set> using namespace std; using ll = long long; ll mod = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0)return a; else return gcd(b, a % b); } bool check(string s, string t) { int i = 0, j = 0; while (i < s.size() && j < t.size()) { if (s[i] == t[j]) { j++; } i++; } if (j == t.size())return 1; else return 0; } void solve() { int n; cin >> n; string s; cin >> s; if (n % 2 == 0) { cout << "NOT POSSIBLE" << endl; return; } string a = s.substr(0, n/2),b=s.substr(0,n/2+1),c=s.substr(n/2,(n/2+1)),d = s.substr(n / 2+1, (n / 2)); if (check(b, d) && check(c, a)) { if (d == a) { cout << d << endl; } else cout << "NOT UNIQUE" << endl; } else if (check(b, d)) { cout << d << endl; } else if (check(c, a)) { cout << a << endl; } else { cout << "NOT POSSIBLE" << endl; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); ll t = 1; //cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...