이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2000005,MOD=1e9+7;
int pref[MAXN],pkt[MAXN];
set<int> S;
int get(int L,int R){
L++;R++;
if(L>R)return 0;
return (pref[R]-((1LL*pref[L-1]*pkt[R-L+1])%MOD)+MOD)%MOD;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
string s;
cin >> n >> s;
if(n%2==0){
cout << "NOT POSSIBLE\n";
return 0;
}
pkt[0]=1;
for(int i=0;i<n;i++){
pref[i+1]=(26LL*pref[i]+s[i]-'A')%MOD;
pkt[i+1]=(26LL*pkt[i])%MOD;
}
int idxL,idxR;
for(int i=1;i<n-1;i++){
int kiri=0,kanan=0;
if(i<=n/2){
kiri=(((1LL*pkt[n/2-i]*get(0,i-1))%MOD)+get(i+1,i+n/2-i))%MOD;
kanan=get(n/2+1,n-1);
}
else{
kiri=get(0,n/2-1);
kanan=(((1LL*pkt[n-i-1]*get(n/2,i-1))%MOD)+get(i+1,n-1))%MOD;
}
if(kiri==kanan){
S.insert(kiri);
if(i<=n/2){
idxL=n/2+1;idxR=n-1;
}
else{
idxL=0;idxR=n/2-1;
}
}
}
int kiri=get(1,n/2),kanan=get(n/2+1,n-1);
if(kiri==kanan){
S.insert(kiri);
idxL=1;idxR=n/2;
}
kiri=get(0,n/2-1);kanan=get(n/2,n-2);
if(kiri==kanan){
S.insert(kiri);
idxL=0;idxR=n/2-1;
}
if(S.size()==0){
cout << "NOT POSSIBLE\n";
}
else if(S.size()==1){
cout << s.substr(idxL,idxR-idxL+1) << '\n';
}
else cout << "NOT UNIQUE\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp: In function 'int main()':
friends.cpp:63:29: warning: 'idxR' may be used uninitialized in this function [-Wmaybe-uninitialized]
63 | cout << s.substr(idxL,idxR-idxL+1) << '\n';
| ~~~~^~~~~
friends.cpp:63:19: warning: 'idxL' may be used uninitialized in this function [-Wmaybe-uninitialized]
63 | cout << s.substr(idxL,idxR-idxL+1) << '\n';
| ~~~~~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |