Submission #931853

# Submission time Handle Problem Language Result Execution time Memory
931853 2024-02-22T12:36:04 Z Tyx2019 Three Friends (BOI14_friends) C++17
0 / 100
27 ms 8384 KB
#include <bits/stdc++.h>
#define int long long
#define debug(x) if(0) cout << #x << " is " << x << "\n";
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	string S;
	cin >> S;
	if(N % 2 == 0){
		cout << "NOT POSSIBLE";
		return 0;
	}
	int X = (N - 1) / 2;
	char curstr[N - 1];
	char rightneow[X];
	bool hvone = false;
	int numcorrect = 0;
	for(int i=1;i<N;i++){
		curstr[i - 1] = S[i];
	}
	for(int i=0;i<X;i++){
		if(curstr[i] == curstr[i + X]) numcorrect ++;
	}
	int numcorwithfunny = 0;
	if(numcorrect == X && !hvone){
		for(int j=0;j<X;j++) rightneow[j] = curstr[j];
		for(int j=0;j<X;j++) if(rightneow[j] == curstr[j]) numcorwithfunny ++;
		hvone = true;
	}
	for(int i=0;i<N;i++){
		//change curstr[i] to S[i]
		if(i < X){
			if(curstr[i] == curstr[i + X]){
				if(S[i] != curstr[i + X]) numcorrect --; 
			}
			else if(S[i] == curstr[i + X]) numcorrect ++;
		}
		else{
			if(curstr[i] == curstr[i - X]){
				if(S[i] != curstr[i - X]) numcorrect --; 
			}
			else if(S[i] == curstr[i - X]) numcorrect ++;
		}
		if(hvone && i < X){
			if(curstr[i] == rightneow[i]){
				if(S[i] != rightneow[i]) numcorwithfunny --;
			}
			else if(S[i] == rightneow[i]) numcorwithfunny ++;
		}
		curstr[i] = S[i];
		if(numcorrect == X && hvone){
			debug(i);
			debug(curstr[2]);
			if(numcorwithfunny != X){
				cout << "NOT UNIQUE";
				return 0;
			}
		}
		if(numcorrect == X && !hvone){
			for(int j=0;j<X;j++) rightneow[j] = curstr[j];
			for(int j=0;j<X;j++) if(rightneow[j] == curstr[j]) numcorwithfunny ++;
			hvone = true;
		}
	}
	if(hvone) for(int i=0;i<X;i++) cout << rightneow[i];
	else cout << "NOT POSSIBLE";
}

Compilation message

friends.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 8192 KB Output is correct
2 Correct 26 ms 8192 KB Output is correct
3 Correct 26 ms 8180 KB Output is correct
4 Correct 27 ms 8192 KB Output is correct
5 Correct 26 ms 8384 KB Output is correct
6 Correct 4 ms 4352 KB Output is correct
7 Correct 26 ms 8192 KB Output is correct
8 Correct 8 ms 6652 KB Output is correct
9 Correct 25 ms 7424 KB Output is correct
10 Incorrect 8 ms 6652 KB Output isn't correct
11 Halted 0 ms 0 KB -