제출 #548629

#제출 시각아이디문제언어결과실행 시간메모리
548629AmylopectinThree Friends (BOI14_friends)C++14
0 / 100
57 ms5324 KiB
#include <iostream>
#include <stdio.h>

using namespace std;
const int mxn = 2e6 + 10;
char s[mxn] = {};
int let[31] = {};
int main()
{
    int i,j,n,m,odd,cou = 0,cl,cr,ans[2] = {},of;
    scanf("%d %s",&n,&s);
    for(i=0; i<n; i++)
    {
        let[s[i] - 'A'] ++;
    }
    for(i=0; i<26; i++)
    {
        if(let[i] % 2 == 1)
        {
            cou ++;
            odd = i;
        }
    }
    if(cou != 1 || n % 2 == 0)
    {
        printf("NOT POSSIBLE\n");
        return 0;
    }
    cl = 0;
    cr = n/2;
    for(j=0; j<2; j++)
    {
        if(j == 1)
        {
            cl = 0;
            cr = n/2 + 1;
        }
        of = 0;
        for(i=0; i<n/2; i++)
        {
            if(s[cl] != s[cr])
            {
                of ++;
                if(of > 1)
                {
                    break;
                }
                if(j == 0)
                {
                    if(s[cr] - 'A' != odd)
                    {
                        of = 2;
                        break;
                    }
                    cr ++;
                }
                else
                {
                    if(s[cl] - 'A' != odd)
                    {
                        of = 2;
                        break;
                    }
                    cl ++;
                }
                i--;
            }
            else
            {
                cl ++;
                cr ++;
            }
        }
        if(of >= 2)
        {
            ans[j] = -1;
        }
        else
            ans[j] = 1;
    }
    if(ans[0] == 1)
    {
        if(ans[1] == 1)
        {
            printf("NOT UNIQUE\n");
        }
        else
        {
            for(i=0; i<n/2; i++)
            {
                printf("%c",s[i]);
            }
            printf("\n");
        }
    }
    else
    {
        if(ans[1] == 1)
        {
            for(i=n/2+1; i<n; i++)
            {
                printf("%c",s[i]);
            }
            printf("\n");
        }
        else
        {
            printf("NOT POSSIBLE\n");
        }
    }
    return 0;
}

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

friends.cpp: In function 'int main()':
friends.cpp:11:16: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[2000010]' [-Wformat=]
   11 |     scanf("%d %s",&n,&s);
      |               ~^     ~~
      |                |     |
      |                char* char (*)[2000010]
friends.cpp:10:15: warning: unused variable 'm' [-Wunused-variable]
   10 |     int i,j,n,m,odd,cou = 0,cl,cr,ans[2] = {},of;
      |               ^
friends.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %s",&n,&s);
      |     ~~~~~^~~~~~~~~~~~~~~
friends.cpp:50:21: warning: 'odd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |                     if(s[cr] - 'A' != odd)
      |                     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...