답안 #931618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931618 2024-02-22T07:10:02 Z penguin133 세 명의 친구들 (BOI14_friends) C++17
0 / 100
22 ms 5420 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
string s;

void solve(){
	cin >> n;
	if(n % 2 == 0){
		cout << "NOT POSSIBLE\n";
		return;
	}
	cin >> s;
	int a = 0, b = 0, c = 0, d = 0;
	for(int i = 0; i < n / 2; i++){
		if(s[i] == s[i + n / 2])a++;
		else break;
	}
	for(int i = 0; i < n / 2; i++){
		if(s[i] == s[i + n / 2 + 1])b++;
		else break;
	}
	for(int i = n - 1; i >= n / 2 + 1; i--){
		if(s[i] == s[i - n / 2])c++;
		else break;
	}
	for(int i = n - 1; i >= n / 2 + 1; i--){
		if(s[i] == s[i - n / 2 - 1])d++;
		else break;
	}
	if(max(b + c, a + d) > n / 2 || (b + c == n / 2 && a + d == n / 2))cout << "NOT UNIQUE\n";
	else if(b + c < n / 2 && a + d < n / 2)cout << "NOT POSSIBLE\n";
	else{
		if(a + d == n / 2){
			for(int i = 0; i < n / 2; i++)cout << s[i];
		}
		else{
			for(int i = n / 2 + 1; i < n; i++)cout << s[i];
		}
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

friends.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5420 KB Output is correct
2 Correct 20 ms 5252 KB Output is correct
3 Correct 21 ms 5364 KB Output is correct
4 Correct 20 ms 5376 KB Output is correct
5 Incorrect 4 ms 4348 KB Output isn't correct
6 Halted 0 ms 0 KB -