제출 #27461

#제출 시각아이디문제언어결과실행 시간메모리
27461TAMREFThree Friends (BOI14_friends)C++11
0 / 100
3 ms3988 KiB
#include <bits/stdc++.h>
using namespace std;
const int mx=2e6+10;
char S[mx];
int N,h;
void input(){
    scanf("%d\n",&N);
    fgets(S,mx-4,stdin);
    S[N]=0;
    if(!(N&1)) exit(0&puts("NOT POSSIBLE"));
    h=(N-1)>>1;
}
void solve_small(){
    char F[2500]={},G[2500]={};
    for(int i=0;i<N;i++){
        strncpy(F,S,i);
        strncpy(F+i,S+i+1,N-1-i);
        if(!strncmp(F,F+h,h)){
            if(G[0] && strncmp(F,G,N-1)) exit(0&puts("NOT UNIQUE"));
            strncpy(G,F,N-1);
        }
    }
    if(!G[0]) exit(0&puts("NOT POSSIBLE"));
    for(int i=0;i<h;i++) putchar(G[i]); puts("");
}
void solve(){
    int s=0,e=N-1,xs=-1,xe=-1;
    for(int i=0;i<h;i++){
        if(S[i]!=S[i+h]){
            s=max(s,i);
            e=min(e,i+h);
            if(s>e) exit(0&puts("NOT POSSIBLE"));
        }
        if(S[i]!=S[i+h+1]){
            if(xs==-1){
                xs=i+1;
                xe=i+h;
            } else{
                xs=min(xs,i+1);
                xe=max(xe,i+h);
            }
        }
    }
}
int main(){
    input();
    if(N<2000) solve_small();
    else solve();
}

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

friends.cpp: In function 'void input()':
friends.cpp:7:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d\n",&N);
                     ^
friends.cpp:8:24: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     fgets(S,mx-4,stdin);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...