답안 #370442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370442 2021-02-24T03:13:34 Z daniel920712 "The Lyuboyn" code (IZhO19_lyuboyn) C++14
100 / 100
560 ms 32840 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;
stack < int > t;
vector < int > all;
char tt[100005];
int N,K,T,S;
int ans[1000005][25];
void F(int here)
{
    int i,j;
    if(here==0)
    {
        all.push_back(0);
        all.push_back(1);
    }
    else if(here==N)
    {
        printf("%d\n",1<<N);
        for(auto i:all)
        {
            for(j=N-1;j>=0;j--)
            {
                if(i&(1<<j)) printf("1");
                else printf("0");
            }
            printf("\n");
        }
        return;
    }
    else
    {
        for(auto i:all) t.push(i+(1<<here));
        while(!t.empty())
        {
            all.push_back(t.top());
            t.pop();
        }

    }
    F(here+1);
}
void F2(int here)
{
    int i,j,now=0;
    if(here==0)
    {
        all.push_back(0);
        all.push_back(1);
    }
    else if(here==N)
    {
        for(auto i:all)
        {
            for(j=N-1;j>=0;j--)
            {
                if(i&(1<<j)) ans[now][N-j-1]=1;
                else ans[now][N-j-1]=0;

                if(now==0)
                {
                    if(i&(1<<j)) ans[1<<N][N-j-1]=1;
                    else ans[1<<N][N-j-1]=0;
                }
            }
            now++;
        }
        return;
    }
    else
    {
        for(auto i:all) t.push(i+(1<<here));
        while(!t.empty())
        {
            all.push_back(t.top());
            t.pop();
        }

    }
    F2(here+1);
}
int main()
{
    int i,j,k,con;
    scanf("%d %d %d",&N,&K,&T);
    scanf("%s",tt);
    if(K%2==0||K>N||(K==N&&K!=1)) printf("-1\n");
    else
    {
        printf("%d\n",1<<N);
        F2(0);

        for(i=1;i<(1<<N);i+=2)
        {
            con=1;
            for(j=1;j<=N;j++)
            {
                if(con>=K) break;
                if(ans[i][N-j]==ans[i-1][N-j]&&ans[i][N-j]==ans[i+1][N-j])
                {
                    ans[i][N-j]=1-ans[i][N-j];
                    con++;
                    if(con>=K) break;
                }
            }
        }

        for(i=0;i<(1<<N);i++)
        {
            for(j=0;j<N;j++) printf("%d",ans[i][j]^(tt[j]-'0'));
            printf("\n");
        }


    }
    return 0;
}
/*
01001
01000
11000
*/

Compilation message

lyuboyn.cpp: In function 'void F(int)':
lyuboyn.cpp:15:9: warning: unused variable 'i' [-Wunused-variable]
   15 |     int i,j;
      |         ^
lyuboyn.cpp: In function 'void F2(int)':
lyuboyn.cpp:49:9: warning: unused variable 'i' [-Wunused-variable]
   49 |     int i,j,now=0;
      |         ^
lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:88:13: warning: unused variable 'k' [-Wunused-variable]
   88 |     int i,j,k,con;
      |             ^
lyuboyn.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   89 |     scanf("%d %d %d",&N,&K,&T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
lyuboyn.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   90 |     scanf("%s",tt);
      |     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Ok
2 Correct 0 ms 364 KB Ok
3 Correct 0 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 509 ms 32840 KB Ok
2 Correct 237 ms 16380 KB Ok
3 Correct 2 ms 492 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 12 ms 1260 KB Ok
3 Correct 246 ms 16584 KB Ok
4 Correct 113 ms 8296 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 3 ms 620 KB Ok
7 Correct 53 ms 4332 KB Ok
8 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 520 ms 32660 KB Ok
2 Correct 541 ms 32572 KB Ok
3 Correct 560 ms 32736 KB Ok
4 Correct 240 ms 16540 KB Ok
5 Correct 240 ms 16356 KB Ok
6 Correct 115 ms 8296 KB Ok
7 Correct 130 ms 8296 KB Ok
8 Correct 54 ms 4332 KB Ok
9 Correct 54 ms 4332 KB Ok
10 Correct 26 ms 2284 KB Ok
11 Correct 2 ms 492 KB Ok
12 Correct 2 ms 492 KB Ok
13 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 509 ms 32840 KB Ok
2 Correct 237 ms 16380 KB Ok
3 Correct 2 ms 492 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 12 ms 1260 KB Ok
8 Correct 246 ms 16584 KB Ok
9 Correct 113 ms 8296 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 3 ms 620 KB Ok
12 Correct 53 ms 4332 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 520 ms 32660 KB Ok
15 Correct 541 ms 32572 KB Ok
16 Correct 560 ms 32736 KB Ok
17 Correct 240 ms 16540 KB Ok
18 Correct 240 ms 16356 KB Ok
19 Correct 115 ms 8296 KB Ok
20 Correct 130 ms 8296 KB Ok
21 Correct 54 ms 4332 KB Ok
22 Correct 54 ms 4332 KB Ok
23 Correct 26 ms 2284 KB Ok
24 Correct 2 ms 492 KB Ok
25 Correct 2 ms 492 KB Ok
26 Correct 1 ms 364 KB Ok
27 Correct 525 ms 32736 KB Ok
28 Correct 243 ms 16356 KB Ok
29 Correct 503 ms 32608 KB Ok
30 Correct 32 ms 2284 KB Ok
31 Correct 3 ms 492 KB Ok
32 Correct 12 ms 1260 KB Ok
33 Correct 53 ms 4332 KB Ok
34 Correct 1 ms 364 KB Ok
35 Correct 1 ms 364 KB Ok
36 Correct 1 ms 364 KB Ok
37 Correct 1 ms 364 KB Ok
38 Correct 241 ms 16356 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 16484 KB Ok
2 Correct 504 ms 32608 KB Ok
3 Correct 513 ms 32608 KB Ok
4 Correct 25 ms 2284 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 54 ms 4332 KB Ok
7 Correct 500 ms 32696 KB Ok
8 Correct 2 ms 620 KB Ok
9 Correct 0 ms 364 KB Ok
10 Correct 2 ms 492 KB Ok
11 Correct 114 ms 8296 KB Ok
12 Correct 243 ms 16356 KB Ok