답안 #957529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957529 2024-04-04T01:19:22 Z YassirSalama 세 명의 친구들 (BOI14_friends) C++17
0 / 100
10 ms 9472 KB
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
#ifdef IOI
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
// #define int long long
const int MAXN=2e5+100,P=31;
ll binpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=(res%mod*a%mod)%mod;
		a=(a%mod*a%mod)%mod;
		b>>=1;
	}
	return res%mod;
}
ll invmod(ll a){
	return binpow(a,mod-2)%mod;
}
int pref[MAXN];
ll inv[MAXN];
ll sum(int l,int r){
	if(l==0) return pref[r]%mod;
	else 
		return ((pref[r]-pref[l-1]+2*mod)%mod*(inv[l]%mod))%mod;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
string s;
cin>>s;
if(n%2==0){
	cout<<"NOT POSSIBLE"<<endl;
	return 0;
}
inv[0]=1;
inv[1]=invmod(P);
for(int i=2;i<MAXN;i++){
	inv[i]=(inv[i-1]%mod*(inv[1]%mod))%mod;
}
int c=1;
memset(pref,0,sizeof(pref));
for(int i=0;i<n;i++){
	int x=s[i]-'A'+1;
	if(i) pref[i]=pref[i-1];
	pref[i]%=mod;
	pref[i]+=(x%mod*c%mod)%mod;
	c=(c%mod*P%mod)%mod;
}
map<int,pair<int,int>> mp;
vector<pair<int,int>> ans;
for(int i=0;i<n;i++){
	int l1=0,r1=0,l2=0,r2=n-1;
	if(i==0){
		l1=1;
	}
	if(i==n-1){
		r2=n-2;
	}
	r1=l1+(n-2)/2;
	if(i>0&&i<=r1) r1++;
	l2=r2-(n-2)/2;
	if(i!=n-1&&i>=l2) l2--;
	if((i>r1&&i<l2)||i==0||i==n-1){
		if(sum(l1,r1)==sum(l2,r2)) mp[sum(l1,r1)]={l1,r1};
		else continue;
	}
	if(i<=r1){
		int t=i-1;
		int t1=i+1;
		int s=0;
		s+=sum(l1,t);
		s%=mod;
		s+=binpow(P,(i%((n-2)/2+1)))*sum(t1,r1);
		s%=mod;
		s+=mod;
		s%=mod;
		if(s==sum(l2,r2)%mod) mp[s]={l2,r2};
	}else{
		int t=i-1;
		int t1=i+1;
		int s=0;
		s+=sum(l2,t);
		s%=mod;
		s+=binpow(P,(i%((n-2)/2+1)))*sum(t1,r2);
		s%=mod;
		s+=mod;
		s%=mod;
		if(s==sum(l1,r1)) mp[s]={l1,r1};
	}
}
if(mp.size()==1){
	pair<int,int> anss=mp.begin()->second;
	cout<<s.substr(anss.F,anss.S-anss.F+1)<<endl;
}else{
	if(mp.empty()){
		cout<<"NOT POSSIBLE"<<endl;
		return 0;
	}
	cout<<"NOT UNIQUE"<<endl;
	return 0;
}
 
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 9472 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -