Submission #169489

# Submission time Handle Problem Language Result Execution time Memory
169489 2019-12-20T16:44:32 Z SamAnd "The Lyuboyn" code (IZhO19_lyuboyn) C++17
3 / 100
2 ms 376 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:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("input.txt", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
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 Incorrect 2 ms 256 KB Output -1 while solution exists
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output -1 while solution exists
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 256 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 256 KB Ok
5 Correct 2 ms 256 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -