Submission #1263506

#TimeUsernameProblemLanguageResultExecution timeMemory
1263506bruhhhhThree Friends (BOI14_friends)C++20
0 / 100
16 ms10216 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n; string s; bool check(string xet, string base){ ll g = base.size(), z = xet.size(); bool pre[g], suf[g]; for (int i = 0; i < g; i++){ pre[i] = (i == 0 || pre[i - 1]) && (xet[i] == base[i]); } for (int i = g - 1; i >= 0; i--){ suf[i] = (i == g - 1 || suf[i + 1]) && (base[i] == xet[i + 1]); } for (int i = 0; i < z; i++){ if ((i == 0 || pre[i - 1]) && (i == z - 1 || suf[i])){ return true; } } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; string s; cin >> n >> s; string ans = ""; if (n % 2 == 0){ cout << "NOT POSSIBLE\n"; return 0; } string xet1 = s.substr(0, n / 2 + 1), xet2 = s.substr(n / 2, n / 2 + 1); string xet3 = s.substr(n / 2 + 1, n / 2), xet4 = s.substr(0, n / 2); bool a = check(xet1, xet3); bool b = check(xet2, xet4); if (a && b){ cout << (xet1 == xet4 ? xet1 : "NOT UNIQUE") << "\n"; } else if (a){ cout << xet3 << "\n"; } else if (b){ cout << xet4 << "\n"; } else{ cout << "NOT POSSIBLE\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...