답안 #169488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169488 2019-12-20T16:40:40 Z SamAnd "The Lyuboyn" code (IZhO19_lyuboyn) C++17
8 / 100
118 ms 7112 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 20;

int n, k, tt;

char s[N];
int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d%d", &n, &k, &tt);
    scanf(" %s", s);
    if (k % 2 == 0)
    {
        printf("-1\n");
        return 0;
    }
    int x = 0;
    for (int i = 0; i < n; ++i)
    {
        if (s[i] == '1')
            x |= (1 << i);
    }
    vector<int> v, vv;
    v.push_back(0);
    v.push_back(1);
    for (int i = 1; i < (k + 1); ++i)
    {
        vv = v;
        v = vv;
        reverse(vv.begin(), vv.end());
        for (int j = 0; j < vv.size(); ++j)
            v.push_back((vv[j] | (1 << i)));
    }
    /*for (int i = 0; i < v.size(); ++i)
    {
        for (int j = 0; j < (k + 1); ++j)
        {
            if ((v[i] & (1 << j)))
                putchar('1');
            else
                putchar('0');
        }
        putchar('\n');
    }*/
    vv.clear();
    vv.push_back(0);
    for (int i = 1; i < v.size(); ++i)
    {
        int x = 0;
        for (int j = 0; j < (k + 1); ++j)
        {
            if (((v[i] & (1 << j)) && (v[i - 1] & (1 << j))) || (!(v[i] & (1 << j)) && !(v[i - 1] & (1 << j))))
            {
                if (!(vv[i - 1] & (1 << j)))
                    x |= (1 << j);
            }
            else
            {
                if ((vv[i - 1] & (1 << j)))
                    x |= (1 << j);
            }
        }
        vv.push_back(x);
    }
    v = vv;
    /*for (int i = 0; i < v.size(); ++i)
    {
        for (int j = 0; j < (k + 1); ++j)
        {
            if ((v[i] & (1 << j)))
                putchar('1');
            else
                putchar('0');
        }
        putchar('\n');
    }*/
    for (int i = (k + 1); i < n; ++i)
    {
        int x = 0;
        for (int j = i - 1; j >= i - k + 1; --j)
            x |= (1 << j);
        vv = v;
        reverse(vv.begin(), vv.end());
        for (int j = 0; j < vv.size(); ++j)
        {
            v.push_back((vv[j] ^ x));
        }
    }
    /*for (int i = 0; i < v.size(); ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if ((v[i] & (1 << j)))
                putchar('1');
            else
                putchar('0');
        }
        putchar('\n');
    }*/
    for (int i = 0; i < v.size(); ++i)
        v[i] ^= x;
    printf("%d\n", v.size());
    for (int i = 0; i < v.size(); ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if ((v[i] & (1 << j)))
                putchar('1');
            else
                putchar('0');
        }
        putchar('\n');
    }
    return 0;
}

Compilation message

lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:32:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vv.size(); ++j)
                         ~~^~~~~~~~~~~
lyuboyn.cpp:48:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < v.size(); ++i)
                     ~~^~~~~~~~~~
lyuboyn.cpp:85:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vv.size(); ++j)
                         ~~^~~~~~~~~~~
lyuboyn.cpp:101:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
lyuboyn.cpp:103:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", v.size());
                    ~~~~~~~~^
lyuboyn.cpp:104:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
lyuboyn.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &k, &tt);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
lyuboyn.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %s", s);
     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 256 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 380 KB Ok
7 Correct 2 ms 256 KB Ok
8 Correct 2 ms 376 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Incorrect 103 ms 7092 KB The values in the output sequence are not pairwise distinct!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB The values in the output sequence are not pairwise distinct!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 118 ms 7112 KB The values in the output sequence are not pairwise distinct!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 103 ms 7092 KB The values in the output sequence are not pairwise distinct!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 3772 KB The values in the output sequence are not pairwise distinct!
2 Halted 0 ms 0 KB -