제출 #240598

#제출 시각아이디문제언어결과실행 시간메모리
240598alishahali1382Three Friends (BOI14_friends)C++14
35 / 100
27 ms16128 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const ll Base=10007, Mod=1000000009;
const int MAXN=200010, LOG=20;
typedef pair<ll, int> Hash;

int n, m, k, u, v, x, y, t, a, b, ans;
ll tav[MAXN];
Hash H[MAXN];
string S;
map<Hash, int> mp;

Hash operator +(Hash x, Hash y){
	Hash res;
	res.second=x.second+y.second;
	res.first=(x.first*tav[y.second] + y.first)%Mod;
	return res;
}
Hash operator -(Hash x, Hash y){
	Hash res;
	res.second=x.second-y.second;
	res.first=(x.first-tav[res.second]*y.first)%Mod;
	if (res.first<0) res.first+=Mod;
	return res;
}


int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	tav[0]=1;
	for (int i=1; i<MAXN; i++) tav[i]=tav[i-1]*Base%Mod;
	cin>>n>>S;
	if (n%2==0) kill("NOT POSSIBLE")
	m=n>>1;
	S="#"+S;
	for (int i=1; i<=n; i++) H[i]=H[i-1]+Hash(S[i], 1);
	
	for (int i=1; i<=m; i++){
		Hash l=H[i-1]+(H[m+1]-H[i]), r=H[n]-H[m+1];
		if (l!=r) continue ;
		mp[l]=i;
	}
	for (int i=m+1; i<=n; i++){
		Hash l=H[m], r=(H[i-1]-H[m])+(H[n]-H[i]);
		if (l!=r) continue ;
		mp[l]=i;
	}
	if (mp.size()>1) kill("NOT UNIQUE")
	if (mp.empty()) kill("NOT POSSIBLE")
	ans=(mp.begin()->second);
	for (int i=1; i<=n; i++){
		if (i==ans) continue ;
		cout<<S[i];
		if ((--m)==0) break ;
	}
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...