Submission #1342523

#TimeUsernameProblemLanguageResultExecution timeMemory
1342523yuqziiThree Friends (BOI14_friends)C++20
0 / 100
11 ms8936 KiB
#include <bits/stdc++.h>

using namespace std;

int n;

bool works(const string& s) {
	int fails = 0;

	for (int i = 0, j = n / 2; i < n / 2; i++, j++) {
		if (s[i] != s[j]){
			fails++;
			if (fails > 1) return false;
			j++;
		}
	}

	return true;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	string u;
	cin >> n >> u;

	string s = "";
	if (works(u))
		s = string(u.begin(), u.begin() + n / 2);
	
	string t = "";
	for (int i = n / 2 + 1; i < n; i++)
		t += u[i];
	for (int i = 0; i <= n / 2; i++)
		t += u[i];


	if (works(t)) {
		string v(t.begin(), t.begin() + n / 2);
		if (s != "" && s != v) {
			cout << "NOT UNIQUE\n";
			return 0;
		}
		s = v;
	}

	if (s == "") cout << "NOT POSSIBLE\n";
	else cout << s << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...