이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define debug(x) if(0) cout << #x << " is " << x << "\n";
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
string S;
cin >> S;
if(N % 2 == 0){
cout << "NOT POSSIBLE";
return 0;
}
int X = (N - 1) / 2;
char curstr[N - 1];
char rightneow[X];
bool hvone = false;
int numcorrect = 0;
for(int i=1;i<N;i++){
curstr[i - 1] = S[i];
}
for(int i=0;i<X;i++){
if(curstr[i] == curstr[i + X]) numcorrect ++;
}
int numcorwithfunny = 0;
if(numcorrect == X && !hvone){
for(int j=0;j<X;j++) rightneow[j] = curstr[j];
for(int j=0;j<X;j++) if(rightneow[j] == curstr[j]) numcorwithfunny ++;
hvone = true;
}
for(int i=0;i<N;i++){
//change curstr[i] to S[i]
if(i < X){
if(curstr[i] == curstr[i + X]){
if(S[i] != curstr[i + X]) numcorrect --;
}
else if(S[i] == curstr[i + X]) numcorrect ++;
}
else{
if(curstr[i] == curstr[i - X]){
if(S[i] != curstr[i - X]) numcorrect --;
}
else if(S[i] == curstr[i - X]) numcorrect ++;
}
if(hvone && i < X){
if(curstr[i] == rightneow[i]){
if(S[i] != rightneow[i]) numcorwithfunny --;
}
else if(S[i] == rightneow[i]) numcorwithfunny ++;
}
curstr[i] = S[i];
if(numcorrect == X && hvone){
debug(i);
debug(curstr[2]);
if(numcorwithfunny != X){
cout << "NOT UNIQUE";
return 0;
}
}
if(numcorrect == X && !hvone){
for(int j=0;j<X;j++) rightneow[j] = curstr[j];
for(int j=0;j<X;j++) if(rightneow[j] == curstr[j]) numcorwithfunny ++;
hvone = true;
}
}
if(hvone) for(int i=0;i<X;i++) cout << rightneow[i];
else cout << "NOT POSSIBLE";
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |