Submission #415759

# Submission time Handle Problem Language Result Execution time Memory
415759 2021-06-01T13:17:52 Z KoD The Collection Game (BOI21_swaps) C++17
25 / 100
176 ms 1092 KB
#include <bits/stdc++.h>
#include "swaps.h"

template <class T> using Vec = std::vector<T>;

void solve(int N, int V) {
    if (V == 5000) {
        Vec<char> done(N);
        Vec<int> ans;
        while (true) {
            Vec<int> remain;
            for (int i = 0; i < N; ++i) {
                if (!done[i]) {
                    remain.push_back(i);
                }
            }
            if (remain.empty()) {
                break;
            }
            while (remain.size() > 1) {
                Vec<int> next;
                Vec<std::array<int, 2>> ask;
                for (int i = 0; i + 1 < (int) remain.size(); i += 2) {
                    schedule(remain[i] + 1, remain[i + 1] + 1);
                    ask.push_back({remain[i + 1], remain[i]});
                }
                const auto ret = visit();
                for (int i = 0; i < (int) ret.size(); ++i) {
                    next.push_back(ask[i][ret[i]]);
                }
                if (remain.size() % 2 == 1) {
                    next.push_back(remain.back());
                }
                remain = std::move(next);
            }
            done[remain[0]] = true;
            ans.push_back(remain[0] + 1);
        }
        answer(ans);
    } else {
        Vec<std::queue<int>> cur(N);
        for (int i = 0; i < N; ++i) {
            cur[i].push(i + 1);
        }
        while (cur.size() > 1) {
            Vec<std::queue<int>> next;
            if (cur.size() % 2 == 1) {
                next.push_back(cur.back());
                cur.pop_back();
            }
            const int size = (int) cur.size() / 2;
            while (true) {
                Vec<int> ask;
                for (int i = 0; i < size; ++i) {
                    const int l = 2 * i;
                    const int r = 2 * i + 1;
                    if (cur[l].empty()) {
                        std::swap(cur[l], cur[r]);
                    }
                    if (cur[r].empty()) {
                        while (!cur[l].empty()) {
                            next[i].push(cur[l].front());
                            cur[l].pop();
                        }
                    } else {
                        schedule(cur[l].front(), cur[r].front());
                        ask.emplace_back(i);
                    }
                }
                if (ask.empty()) {
                    break;
                }
                const auto ret = visit();
                for (int i = 0; i < (int) ret.size(); ++i) {
                    const auto k = ask[i];
                    const auto idx = 2 * k + 1 - ret[i];
                    next[k].push(cur[idx].front());
                    cur[idx].pop();
                }
            }
        }
        Vec<int> ans;
        while (!cur[0].empty()) {
            ans.push_back(cur[0].front());
            cur[0].pop();
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Correct
2 Correct 11 ms 200 KB Correct
3 Correct 52 ms 280 KB Correct
4 Correct 110 ms 324 KB Correct
5 Correct 150 ms 312 KB Correct
6 Correct 110 ms 308 KB Correct
7 Correct 120 ms 308 KB Correct
8 Correct 107 ms 312 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Correct
2 Correct 15 ms 200 KB Correct
3 Correct 37 ms 292 KB Correct
4 Correct 102 ms 316 KB Correct
5 Correct 107 ms 308 KB Correct
6 Correct 104 ms 308 KB Correct
7 Correct 102 ms 312 KB Correct
8 Correct 154 ms 304 KB Correct
9 Runtime error 2 ms 1092 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 200 KB Correct
2 Correct 6 ms 200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 200 KB Correct
2 Correct 6 ms 200 KB Correct
3 Correct 1 ms 200 KB Correct
4 Correct 12 ms 200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 200 KB Correct
2 Correct 12 ms 200 KB Correct
3 Correct 38 ms 280 KB Correct
4 Correct 136 ms 300 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 200 KB Correct
2 Correct 12 ms 200 KB Correct
3 Correct 38 ms 280 KB Correct
4 Correct 136 ms 300 KB Correct
5 Correct 3 ms 200 KB Correct
6 Correct 8 ms 200 KB Correct
7 Correct 46 ms 292 KB Correct
8 Correct 117 ms 308 KB Correct
9 Correct 95 ms 296 KB Correct
10 Correct 88 ms 304 KB Correct
11 Correct 110 ms 304 KB Correct
12 Correct 94 ms 304 KB Correct
13 Correct 2 ms 200 KB Correct
14 Correct 15 ms 200 KB Correct
15 Correct 43 ms 288 KB Correct
16 Correct 176 ms 308 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 13 ms 200 KB Correct
3 Correct 32 ms 292 KB Correct
4 Correct 163 ms 304 KB Correct
5 Runtime error 3 ms 1048 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 13 ms 200 KB Correct
3 Correct 32 ms 292 KB Correct
4 Correct 163 ms 304 KB Correct
5 Runtime error 3 ms 1048 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 3 ms 200 KB Correct
2 Correct 16 ms 200 KB Correct
3 Correct 22 ms 324 KB Correct
4 Correct 158 ms 300 KB Correct
5 Runtime error 2 ms 1052 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 200 KB Correct
2 Correct 16 ms 200 KB Correct
3 Correct 22 ms 324 KB Correct
4 Correct 158 ms 300 KB Correct
5 Runtime error 2 ms 1052 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Correct
2 Correct 9 ms 200 KB Correct
3 Correct 45 ms 284 KB Correct
4 Correct 116 ms 312 KB Correct
5 Runtime error 2 ms 996 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Correct
2 Correct 9 ms 200 KB Correct
3 Correct 45 ms 284 KB Correct
4 Correct 116 ms 312 KB Correct
5 Runtime error 2 ms 996 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -