Submission #173843

# Submission time Handle Problem Language Result Execution time Memory
173843 2020-01-05T14:10:48 Z emil_physmath "The Lyuboyn" code (IZhO19_lyuboyn) C++17
0 / 100
1000 ms 21752 KB
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
typedef unsigned int uint;

int n;
uint a[1 << 20];
bool used[1 << 20];
int changeInd[1 << 20];

ostream& PrintBin(uint a)
{
    for (int i = n - 1; i >= 0; --i)
        cout << (1 & (1 << i));
    return cout;
}
int Bits(uint a)
{
    int res = 0;
    while (a)
    {
        res += a & 1;
        a >>= 1;
    }
    return res;
}
void Print(const string& s_str)
{
    uint s = 0;
    for (int i = 0; i < s_str.length(); ++i)
        if (s_str[i] == '1')
            s += (1U << i);
    cout << (1 << n) << endl;
    for (auto it = find(a, a + (1 << n), s); it != a + (1 << n); ++it)
        cout << *it << '\n';
    for (int i = 0; a[i] != s; ++i)
        cout << a[i] << '\n';
}
int main()
{
    int k, t;
    cin >> n >> k >> t;
    vector<uint> changes;
    for (uint mask = 0; mask < (1U << n); ++mask)
        if (Bits(mask) == k)
            changes.push_back(mask);
    string s;
    cin >> s;
    int top = 0;
    while (top >= 0)
    {
        cerr << "top = " << top << endl;
        for (int i = 0; i < top; ++i)
            PrintBin(a[i]) << '\n';
        if (top == 1 << n)
        {
            if (Bits(a[0] ^ a[top - 1]) == k)
            {
                Print(s);
                exit(0);
            }
            else
            {
                ++changeInd[top - 1];
                --top;
            }
        }
        if (changeInd[top] == changes.size())
        {
            changeInd[top] = 0;
            used[a[top - 1]] = false;
            --top;
        }
        else
        {
            uint newTop = a[top - 1] ^ changes[changeInd[top] + 1];
            if (!used[newTop])
            {
                a[top] = newTop;
                ++changeInd[top];
                used[newTop] = true;
                ++top;
            }
            else
                ++changeInd[top];
        }
    }
    cout << -1 << endl;
}

Compilation message

lyuboyn.cpp: In function 'void Print(const string&)':
lyuboyn.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s_str.length(); ++i)
                     ~~^~~~~~~~~~~~~~~~
lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:70:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (changeInd[top] == changes.size())
             ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 376 KB Expected integer, but "top" found
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 468 KB Expected integer, but "top" found
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 21092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 20916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 504 KB Expected integer, but "top" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 21752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 20916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 21272 KB Time limit exceeded
2 Halted 0 ms 0 KB -