Submission #1027624

# Submission time Handle Problem Language Result Execution time Memory
1027624 2024-07-19T08:03:34 Z caterpillow "The Lyuboyn" code (IZhO19_lyuboyn) C++17
100 / 100
181 ms 34420 KB
#include <bits/stdc++.h>

using namespace std;

using db = long double;
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end() 
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;

template<typename Tuple, size_t... Is>
void print_tuple(const Tuple& t, index_sequence<Is...>) {
    ((cerr << (Is == 0 ? "{" : ", ") << get<Is>(t)), ...);
    cerr << "}";
}

template<typename... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
    print_tuple(t, index_sequence_for<Args...>{});
    return os;
}

ostream& operator<<(ostream& os, string& s) {
    for (char c : s) os << c; 
    return os;
}

template<template<typename> class Container, typename T>
ostream& operator<<(ostream& os, Container<T> o) {
    os << "{"; 
    int g = size(o); 
    for (auto i : o) os << i << ((--g) == 0 ? "" : ", "); 
    os << "}";
    return os;
}

template<typename T, typename V>
ostream& operator<<(ostream& os, const pair<T, V> p) {
    os << "{" << p.f << ", " << p.s << "}";
    return os;
}

template <typename T, typename... V>
void printer(const char *names, T &&head, V &&...tail) {
    int i = 0;
    while (names[i] != '\0' && names[i] != ',') i++;
    constexpr bool is_str = is_same_v<decay_t<T>, const char*>;
    if constexpr (is_str) cerr << head; // ignore directly passed strings
    else cerr.write(names, i) << " = " << head; 
    if constexpr (sizeof...(tail)) cerr << (is_str ? "" : ","), printer(names + i + 1, tail...);
    else cerr << endl;
}

#ifdef LOCAL
#define dbg(...) std::cerr << __LINE__ << ": ", printer(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif

/*

each step is xoring prev number with a new mask of popcount k
s is irrelevant

if k is even, then the parity will never change, and hence its impossible
this is a necessary condition, and since we do info and not math we just assume its also necessary 

*/

int n, k, t, s;
vt<bool> seen;
vt<int> transitions;

void prnt(int x) {
    ROF (i, 0, n) {
        cout << (1 & (x >> i));
    }
    cout << endl;
}

bool dfs(int cur, int d = 0) {
    if (d == (1 << n) - 1) return __builtin_popcount(cur ^ s) == k;
    seen[cur] = true;
    for (int t : transitions) {
        if (!seen[cur ^ t]) {
            if (dfs(cur ^ t, d + 1)) {
                prnt(cur ^ t);
                return true;
            }
        }
    }
    seen[cur] = false;
    return false;
}

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> k >> t;
    if (k % 2 == 0) {
        cout << "-1\n";
        return 0;
    }
    string st; cin >> st;
    F0R (i, size(st)) {
        s <<= 1;
        s += (st[i] == '1');
    }
    cout << (1 << n) << endl;
    F0R (i, 1 << n) {
        if (__builtin_popcount(i) == k) {
            transitions.pb(i);
        }
    }
    seen.resize(1 << n);
    prnt(s);
    assert(dfs(s));
}

Compilation message

lyuboyn.cpp:108:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  108 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 344 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 132 ms 33968 KB Ok
2 Correct 74 ms 16972 KB Ok
3 Correct 1 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 4 ms 1372 KB Ok
3 Correct 64 ms 17024 KB Ok
4 Correct 35 ms 8532 KB Ok
5 Correct 1 ms 348 KB Ok
6 Correct 1 ms 604 KB Ok
7 Correct 16 ms 4444 KB Ok
8 Correct 1 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 156 ms 34336 KB Ok
2 Correct 157 ms 34272 KB Ok
3 Correct 181 ms 34020 KB Ok
4 Correct 70 ms 17236 KB Ok
5 Correct 67 ms 16980 KB Ok
6 Correct 35 ms 8624 KB Ok
7 Correct 34 ms 8532 KB Ok
8 Correct 16 ms 4520 KB Ok
9 Correct 17 ms 4444 KB Ok
10 Correct 8 ms 2396 KB Ok
11 Correct 1 ms 348 KB Ok
12 Correct 1 ms 348 KB Ok
13 Correct 0 ms 452 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 132 ms 33968 KB Ok
2 Correct 74 ms 16972 KB Ok
3 Correct 1 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 344 KB Ok
7 Correct 4 ms 1372 KB Ok
8 Correct 64 ms 17024 KB Ok
9 Correct 35 ms 8532 KB Ok
10 Correct 1 ms 348 KB Ok
11 Correct 1 ms 604 KB Ok
12 Correct 16 ms 4444 KB Ok
13 Correct 1 ms 348 KB Ok
14 Correct 156 ms 34336 KB Ok
15 Correct 157 ms 34272 KB Ok
16 Correct 181 ms 34020 KB Ok
17 Correct 70 ms 17236 KB Ok
18 Correct 67 ms 16980 KB Ok
19 Correct 35 ms 8624 KB Ok
20 Correct 34 ms 8532 KB Ok
21 Correct 16 ms 4520 KB Ok
22 Correct 17 ms 4444 KB Ok
23 Correct 8 ms 2396 KB Ok
24 Correct 1 ms 348 KB Ok
25 Correct 1 ms 348 KB Ok
26 Correct 0 ms 452 KB Ok
27 Correct 166 ms 34088 KB Ok
28 Correct 90 ms 16980 KB Ok
29 Correct 150 ms 34328 KB Ok
30 Correct 9 ms 2396 KB Ok
31 Correct 1 ms 348 KB Ok
32 Correct 4 ms 1372 KB Ok
33 Correct 19 ms 4480 KB Ok
34 Correct 0 ms 348 KB Ok
35 Correct 0 ms 348 KB Ok
36 Correct 1 ms 348 KB Ok
37 Correct 0 ms 348 KB Ok
38 Correct 72 ms 17056 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 74 ms 17164 KB Ok
2 Correct 157 ms 34092 KB Ok
3 Correct 146 ms 34420 KB Ok
4 Correct 8 ms 2396 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 16 ms 4540 KB Ok
7 Correct 134 ms 34240 KB Ok
8 Correct 1 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 1 ms 348 KB Ok
11 Correct 31 ms 8672 KB Ok
12 Correct 84 ms 17092 KB Ok