Submission #429885

# Submission time Handle Problem Language Result Execution time Memory
429885 2021-06-16T10:15:51 Z dolphingarlic The Collection Game (BOI21_swaps) C++14
100 / 100
9 ms 408 KB
#include "swaps.h"

#include <numeric>
#include <algorithm>

void solve(int N, int V) {
    std::vector<int> ans(N);
    std::iota(ans.begin(), ans.end(), 1);
    int P2 = 1;
    while (P2 < N) P2 <<= 1;
    for (int P = 1; P < P2; P <<= 1)
        for (int k = P; k; k >>= 1) {
            std::vector<std::pair<int, int>> visited;
            for (int j = k % P; j < P2 - k; j += 2 * k)
                for (int i = 0; i < k && i + j + k < N; i++)
                    if ((i + j) / (2 * P) == (i + j + k) / (2 * P)) {
                        schedule(ans[i + j], ans[i + j + k]);
                        visited.push_back({i + j, i + j + k});
                    }
            std::vector<int> visit_res = visit();
            for (int i = 0; i < visit_res.size(); i++)
                if (!visit_res[i])
                    std::swap(ans[visited[i].first], ans[visited[i].second]);
        }
    answer(ans);
}

Compilation message

swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:21:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |             for (int i = 0; i < visit_res.size(); i++)
      |                             ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 256 KB Correct
3 Correct 3 ms 200 KB Correct
4 Correct 5 ms 300 KB Correct
5 Correct 5 ms 296 KB Correct
6 Correct 7 ms 296 KB Correct
7 Correct 6 ms 300 KB Correct
8 Correct 7 ms 300 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 200 KB Correct
3 Correct 4 ms 200 KB Correct
4 Correct 7 ms 200 KB Correct
5 Correct 6 ms 296 KB Correct
6 Correct 5 ms 288 KB Correct
7 Correct 6 ms 284 KB Correct
8 Correct 8 ms 292 KB Correct
9 Correct 8 ms 288 KB Correct
10 Correct 6 ms 316 KB Correct
11 Correct 6 ms 292 KB Correct
12 Correct 5 ms 408 KB Correct
13 Correct 6 ms 300 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Correct
2 Correct 2 ms 256 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Correct
2 Correct 2 ms 256 KB Correct
3 Correct 1 ms 200 KB Correct
4 Correct 2 ms 200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 200 KB Correct
3 Correct 4 ms 200 KB Correct
4 Correct 7 ms 408 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 200 KB Correct
3 Correct 4 ms 200 KB Correct
4 Correct 7 ms 408 KB Correct
5 Correct 1 ms 200 KB Correct
6 Correct 2 ms 200 KB Correct
7 Correct 3 ms 280 KB Correct
8 Correct 4 ms 292 KB Correct
9 Correct 6 ms 352 KB Correct
10 Correct 6 ms 292 KB Correct
11 Correct 5 ms 296 KB Correct
12 Correct 6 ms 288 KB Correct
13 Correct 1 ms 200 KB Correct
14 Correct 1 ms 200 KB Correct
15 Correct 3 ms 200 KB Correct
16 Correct 9 ms 284 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Correct
2 Correct 2 ms 284 KB Correct
3 Correct 3 ms 284 KB Correct
4 Correct 4 ms 292 KB Correct
5 Correct 7 ms 272 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Correct
2 Correct 2 ms 284 KB Correct
3 Correct 3 ms 284 KB Correct
4 Correct 4 ms 292 KB Correct
5 Correct 7 ms 272 KB Correct
6 Correct 1 ms 200 KB Correct
7 Correct 1 ms 280 KB Correct
8 Correct 5 ms 200 KB Correct
9 Correct 5 ms 292 KB Correct
10 Correct 6 ms 288 KB Correct
11 Correct 7 ms 284 KB Correct
12 Correct 5 ms 292 KB Correct
13 Correct 6 ms 300 KB Correct
14 Correct 6 ms 296 KB Correct
15 Correct 6 ms 292 KB Correct
16 Correct 6 ms 292 KB Correct
17 Correct 5 ms 292 KB Correct
18 Correct 6 ms 288 KB Correct
19 Correct 1 ms 200 KB Correct
20 Correct 1 ms 200 KB Correct
21 Correct 3 ms 200 KB Correct
22 Correct 6 ms 292 KB Correct
23 Correct 6 ms 276 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 1 ms 280 KB Correct
3 Correct 3 ms 280 KB Correct
4 Correct 7 ms 292 KB Correct
5 Correct 6 ms 276 KB Correct
6 Correct 6 ms 276 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 1 ms 280 KB Correct
3 Correct 3 ms 280 KB Correct
4 Correct 7 ms 292 KB Correct
5 Correct 6 ms 276 KB Correct
6 Correct 6 ms 276 KB Correct
7 Correct 1 ms 200 KB Correct
8 Correct 2 ms 200 KB Correct
9 Correct 3 ms 256 KB Correct
10 Correct 6 ms 300 KB Correct
11 Correct 6 ms 316 KB Correct
12 Correct 7 ms 296 KB Correct
13 Correct 5 ms 300 KB Correct
14 Correct 6 ms 200 KB Correct
15 Correct 8 ms 284 KB Correct
16 Correct 5 ms 316 KB Correct
17 Correct 5 ms 292 KB Correct
18 Correct 5 ms 292 KB Correct
19 Correct 6 ms 288 KB Correct
20 Correct 1 ms 200 KB Correct
21 Correct 1 ms 200 KB Correct
22 Correct 3 ms 200 KB Correct
23 Correct 6 ms 292 KB Correct
24 Correct 6 ms 272 KB Correct
25 Correct 5 ms 252 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 1 ms 280 KB Correct
3 Correct 3 ms 284 KB Correct
4 Correct 6 ms 296 KB Correct
5 Correct 7 ms 384 KB Correct
6 Correct 6 ms 276 KB Correct
7 Correct 6 ms 272 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 1 ms 280 KB Correct
3 Correct 3 ms 284 KB Correct
4 Correct 6 ms 296 KB Correct
5 Correct 7 ms 384 KB Correct
6 Correct 6 ms 276 KB Correct
7 Correct 6 ms 272 KB Correct
8 Correct 1 ms 200 KB Correct
9 Correct 1 ms 200 KB Correct
10 Correct 2 ms 280 KB Correct
11 Correct 3 ms 284 KB Correct
12 Correct 6 ms 296 KB Correct
13 Correct 8 ms 292 KB Correct
14 Correct 4 ms 292 KB Correct
15 Correct 5 ms 292 KB Correct
16 Correct 8 ms 288 KB Correct
17 Correct 7 ms 292 KB Correct
18 Correct 6 ms 296 KB Correct
19 Correct 5 ms 296 KB Correct
20 Correct 5 ms 292 KB Correct
21 Correct 6 ms 296 KB Correct
22 Correct 1 ms 200 KB Correct
23 Correct 2 ms 200 KB Correct
24 Correct 4 ms 200 KB Correct
25 Correct 5 ms 296 KB Correct
26 Correct 5 ms 268 KB Correct
27 Correct 6 ms 252 KB Correct
28 Correct 7 ms 256 KB Correct