Submission #169490

# Submission time Handle Problem Language Result Execution time Memory
169490 2019-12-20T16:45:24 Z SamAnd "The Lyuboyn" code (IZhO19_lyuboyn) C++17
100 / 100
139 ms 7648 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 + 2); i <= n; ++i)
    {
        int x = 0;
        for (int j = i - 1; j >= i - k; --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);
     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 256 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 376 KB Ok
7 Correct 2 ms 252 KB Ok
8 Correct 2 ms 256 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 110 ms 7136 KB Ok
2 Correct 55 ms 3700 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Ok
2 Correct 5 ms 504 KB Ok
3 Correct 54 ms 3824 KB Ok
4 Correct 27 ms 1908 KB Ok
5 Correct 2 ms 380 KB Ok
6 Correct 2 ms 380 KB Ok
7 Correct 14 ms 1148 KB Ok
8 Correct 2 ms 256 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 112 ms 7056 KB Ok
2 Correct 111 ms 7112 KB Ok
3 Correct 110 ms 7016 KB Ok
4 Correct 56 ms 3696 KB Ok
5 Correct 55 ms 3692 KB Ok
6 Correct 27 ms 1908 KB Ok
7 Correct 26 ms 1908 KB Ok
8 Correct 14 ms 1144 KB Ok
9 Correct 14 ms 1144 KB Ok
10 Correct 7 ms 760 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 256 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 110 ms 7136 KB Ok
2 Correct 55 ms 3700 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 256 KB Ok
7 Correct 5 ms 504 KB Ok
8 Correct 54 ms 3824 KB Ok
9 Correct 27 ms 1908 KB Ok
10 Correct 2 ms 380 KB Ok
11 Correct 2 ms 380 KB Ok
12 Correct 14 ms 1148 KB Ok
13 Correct 2 ms 256 KB Ok
14 Correct 112 ms 7056 KB Ok
15 Correct 111 ms 7112 KB Ok
16 Correct 110 ms 7016 KB Ok
17 Correct 56 ms 3696 KB Ok
18 Correct 55 ms 3692 KB Ok
19 Correct 27 ms 1908 KB Ok
20 Correct 26 ms 1908 KB Ok
21 Correct 14 ms 1144 KB Ok
22 Correct 14 ms 1144 KB Ok
23 Correct 7 ms 760 KB Ok
24 Correct 2 ms 376 KB Ok
25 Correct 2 ms 376 KB Ok
26 Correct 2 ms 256 KB Ok
27 Correct 139 ms 7608 KB Ok
28 Correct 56 ms 3692 KB Ok
29 Correct 112 ms 7016 KB Ok
30 Correct 8 ms 632 KB Ok
31 Correct 2 ms 376 KB Ok
32 Correct 5 ms 504 KB Ok
33 Correct 16 ms 1144 KB Ok
34 Correct 2 ms 256 KB Ok
35 Correct 2 ms 376 KB Ok
36 Correct 2 ms 376 KB Ok
37 Correct 2 ms 256 KB Ok
38 Correct 61 ms 3756 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 61 ms 3852 KB Ok
2 Correct 139 ms 7648 KB Ok
3 Correct 112 ms 7012 KB Ok
4 Correct 8 ms 632 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 16 ms 1144 KB Ok
7 Correct 111 ms 7120 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 256 KB Ok
10 Correct 2 ms 380 KB Ok
11 Correct 33 ms 2136 KB Ok
12 Correct 57 ms 3656 KB Ok