제출 #46215

#제출 시각아이디문제언어결과실행 시간메모리
46215arman_ferdous세 명의 친구들 (BOI14_friends)C++11
100 / 100
24 ms10556 KiB
#include <bits/stdc++.h>
using namespace std;

int n;
string s;
set<string> st;

// search for [l2,r2] in [l1,r1] with exactly one mismatch and skip it
bool match_and_skip(int l1, int r1, int l2, int r2) {
	int cnt = 0;
	string ret = "";
	while(l1 <= r1 && l2 <= r2) {
		if(s[l1] != s[l2]) cnt++, l2--;
		else ret += s[l1];
		if(cnt > 1) return false;
		l1++, l2++;
	} 
	if(cnt == 1 || (l1 <= r1 && cnt == 0)) st.insert(ret);
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> s;
	if(~n&1) { cout << "NOT POSSIBLE\n"; return 0; }
	int len = n>>1;

	match_and_skip(0,len,len+1,n-1);					// (.x..)(...)
	match_and_skip(len,n-1,0,len-1);					// (...)(..x.)

	if(st.size() == 0) cout << "NOT POSSIBLE\n";
	else if(st.size() > 1) cout << "NOT UNIQUE\n";
	else cout << *(st.begin()) << "\n";
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'bool match_and_skip(int, int, int, int)':
friends.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...