제출 #57420

#제출 시각아이디문제언어결과실행 시간메모리
57420PeppaPig세 명의 친구들 (BOI14_friends)C++14
0 / 100
209 ms78684 KiB
#include <bits/stdc++.h>

#define pll pair<long long, long long>
#define x first
#define y second

using namespace std;

const int N = 2e6 + 5;

pll add(pll a, pll b) { return pll(a.x + b.x, a.y + b.y); }
pll sub(pll a, pll b) { return pll(a.x - b.x, a.y - b.y); }
pll mul(pll a, pll b) { return pll(a.x * b.x, a.y * b.y); }

pll id[N];

int n, cnt, pos;
pll dp[N];
string str;

int main() {
	id[0] = {1, 1};
	id[1] = {101LL, 103LL};
	for(int i = 2;i < N;i++) id[i] = mul(id[i - 1], id[1]);
	scanf("%d", &n);
	if(!(n & 1)) return !printf("NOT POSSIBLE");
	cin >> str;
	dp[0] = {str[0], str[0]};
	for(int i = 1;i < n;i++) dp[i] = add(mul(pll(str[i], str[i]), id[i]), dp[i - 1]);
	if(mul(sub(dp[n >> 1], dp[0]), id[n >> 1]) == sub(dp[n - 1], dp[n >> 1])) cnt++, pos = 0;
	if(mul(dp[(n >> 1) - 1], id[n >> 1]) == sub(dp[n - 2], dp[(n >> 1) - 1])) cnt++, pos = n - 1;
	for(int i = 1;i < n >> 1;i++) if(sub(dp[n - 1], dp[n >> 1]) == mul(add(sub(dp[n >> 1], dp[i]), mul(dp[i - 1], id[1])), id[n >> 1])) cnt++, pos = i;
	if(mul(dp[(n >> 1) - 1], id[(n >> 1) + 1]) == sub(dp[n - 1], dp[n >> 1])) cnt++, pos = n >> 1;
	for(int i = (n >> 1) + 1;i < n;i++) if(mul(dp[(n >> 1) - 1], id[(n >> 1) + 1]) == add(mul(sub(dp[i - 1], dp[(n >> 1) - 1]), id[1]), sub(dp[n - 1], dp[i]))) cnt++, pos = i;
	
	if(!cnt) printf("NOT POSSIBLE");
	else if(cnt == 1) {
		if(!pos) cout << str.substr(1, n >> 1) << endl;
		else if(pos == n - 1) cout << str.substr(0, n >> 1) << endl;
		else cout << (str.substr(0, pos) + str.substr(pos + 1, n - pos - 1)).substr(0, n >> 1) << endl;
	}
	else printf("NOT UNIQUE");

	return 0;
}

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

friends.cpp: In function 'int main()':
friends.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...