Submission #631934

#TimeUsernameProblemLanguageResultExecution timeMemory
631934maomao90The Collection Game (BOI21_swaps)C++17
100 / 100
7 ms416 KiB

// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
#include "swaps.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 505;
const int MAXL = 9;

int n, on;
vi p;
vii moves;

void my_schedule(int i, int j) {
    moves.pb({i, j});
    if (i <= on && j <= on) {
        schedule(i, j);
    }
}
vi my_visit() {
    vi tmp = visit();
    reverse(ALL(tmp));
    vi res;
    for (auto [i, j] : moves) {
        if (i <= on && j <= on) {
            res.pb(tmp.back());
            tmp.pop_back();
        } else if (i > on && j > on) {
            res.pb(i < j);
        } else if (i > on) {
            res.pb(0);
        } else {
            res.pb(1);
        }
    }
    moves.clear();
    return res;
}

void solve(int N, int V) {
    on = n = N;
    p = vi(n, 0);
    iota(ALL(p), 1);
    while (__builtin_popcount(n) > 1) {
        n++;
        p.pb(n);
    }
    REP (k, 0, MAXL) {
        for (int i = 1; (i << k) < n; i += 2) {
            reverse(p.begin() + (i << k), p.begin() + min(i + 1 << k, n));
        }
        RREP (l, k, 0) {
            vii vm;
            REP (i, 0, n) {
                if (i >> l & 1) {
                    int j = i - (1 << l);
                    my_schedule(p[j], p[i]);
                    vm.pb({j, i});
                }
            }
            vi res = my_visit();
            assert(SZ(res) == SZ(vm));
            REP (i, 0, SZ(res)) {
                if (!res[i]) {
                    swap(p[vm[i].FI], p[vm[i].SE]);
                }
            }
        }
    }
    p.resize(on);
    answer(p);
}

Compilation message (stderr)

swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:80:61: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   80 |             reverse(p.begin() + (i << k), p.begin() + min(i + 1 << k, n));
      |                                                           ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...