Submission #735651

#TimeUsernameProblemLanguageResultExecution timeMemory
735651josanneo22Three Friends (BOI14_friends)C++17
0 / 100
1064 ms75144 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define mp make_pair
#define fi first
#define se second
set<int> st;
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	if (n % 2 == 0) {
		cout << "NOT POSSIBLE\n";
		return 0;
	}
	int pt = 0, jump = n / 2;
	string p = "";
	for (int i = 1; i < n; i++) {
		p += s[i];
	}
	for (int i = 0; i < p.size(); i++) {
		if (i + jump <= p.size() - 1 && p[i] != p[i + jump]) {
			st.insert(i);
			st.insert(i + jump);
		}
	}
	int ans = 0;
	string save;
	while (pt <= n - 1) {
		if (st.size() == 0) {
			save = p; ans++;
		}
		p[pt] = s[pt];
		auto pos = st.find(pt);
		if (pos != st.end()) st.erase(pos); 
		if (pt + jump <= n - 2) {
			pos = st.find(pt + jump);
			if (pos != st.end()) st.erase(pos);
		}
		if (pt - jump <= n - 2){ 
			pos = st.find(pt - jump);
			if (pos != st.end()) st.erase(pos); 
		}
		if (pt + jump <= n - 2 && p[pt] != p[pt + jump]) {
			st.insert(pt);
			st.insert(pt + jump);
		}
		if(pt -jump>=0 && p[pt] != p[pt - jump]){
			st.insert(pt);
			st.insert(pt - jump);
		}  
		pt++;
	}
	if (ans == 1) cout << save.substr(0, save.size() / 2) << '\n';
	else if (ans == 0) cout << "NOT POSSIBLE\n";
	else cout << "NOT UNIQUE";
}

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:22:20: 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]
   22 |  for (int i = 0; i < p.size(); i++) {
      |                  ~~^~~~~~~~~~
friends.cpp:23:16: 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]
   23 |   if (i + jump <= p.size() - 1 && p[i] != p[i + jump]) {
      |       ~~~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...