답안 #502070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502070 2022-01-05T08:21:16 Z tengiz05 Monster Game (JOI21_monster) C++17
100 / 100
111 ms 292 KB
#include "monster.h"
#include <bits/stdc++.h>

namespace {
    std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
    std::vector<int> sort(std::vector<int> a) {
        if (a.size() == 1) {
            return a;
        }
        int m = a.size() / 2;
        std::shuffle(a.begin(), a.end(), rnd);
        std::vector<int> l(a.begin(), a.begin() + m), r(a.begin() + m, a.end());
        l = sort(l);
        r = sort(r);
        int i = 0, j = 0;
        for (int k = 0; k < int(a.size()); k++) {
            if (i == int(l.size())) {
                a[k] = r[j++];
            } else if (j == int(r.size())) {
                a[k] = l[i++];
            } else if (Query(l[i], r[j])) {
                a[k] = r[j++];
            } else {
                a[k] = l[i++];
            }
        }
        return a;
    }
    std::vector<int> slow(std::vector<int> a) {
        int n = a.size();
        std::vector res(n, std::vector<bool>(n));
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                res[i][j] = Query(a[i], a[j]);
                res[j][i] = !res[i][j];
            }
        }
        std::vector<std::pair<int, int>> v;
        for (int i = 0; i < n; i++)
            v.emplace_back(std::accumulate(res[i].begin(), res[i].end(), 0), a[i]);
        std::sort(v.begin(), v.end());
        for (int i = 0; i < n; i++) {
            a[i] = v[i].second;
        }
        if (Query(a[1], a[0])) std::swap(a[1], a[0]);
        if (Query(a[n - 1], a[n - 2])) std::swap(a[n - 1], a[n - 2]);
        return a;
    }
}  // namespace

std::vector<int> Solve(int n) {
    std::vector<int> a(n);
    std::iota(a.begin(), a.end(), 0);
    a = sort(a);
    std::vector<int> s(a.begin(), a.begin() + std::min(n, 10));
    
    s = slow(s);
    
    int x = s[0];
    a.erase(std::find(a.begin(), a.end(), x));
    a.insert(a.begin(), x);
    
    for (int i = 1; i < n; i++) {
        int j = i;
        while (j < n && Query(a[j], x))
            j++;
        std::reverse(a.begin() + i, a.begin() + std::min(j + 1, n));
        i = j;
        x = a[i];
    }
    
    std::vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        ans[a[i]] = i;
    }
    
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 15 ms 200 KB Output is correct
17 Correct 13 ms 200 KB Output is correct
18 Correct 14 ms 200 KB Output is correct
19 Correct 12 ms 200 KB Output is correct
20 Correct 20 ms 200 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 15 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 13 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 15 ms 200 KB Output is correct
17 Correct 13 ms 200 KB Output is correct
18 Correct 14 ms 200 KB Output is correct
19 Correct 12 ms 200 KB Output is correct
20 Correct 20 ms 200 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 15 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 13 ms 200 KB Output is correct
33 Correct 86 ms 200 KB Output is correct
34 Correct 74 ms 200 KB Output is correct
35 Correct 68 ms 292 KB Output is correct
36 Correct 34 ms 200 KB Output is correct
37 Correct 84 ms 200 KB Output is correct
38 Correct 111 ms 200 KB Output is correct
39 Correct 77 ms 200 KB Output is correct
40 Correct 67 ms 200 KB Output is correct
41 Correct 91 ms 200 KB Output is correct
42 Correct 86 ms 200 KB Output is correct
43 Correct 34 ms 200 KB Output is correct
44 Correct 80 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 200 KB Output is correct
2 Correct 89 ms 200 KB Output is correct
3 Correct 79 ms 200 KB Output is correct
4 Correct 72 ms 200 KB Output is correct
5 Correct 97 ms 200 KB Output is correct
6 Correct 58 ms 200 KB Output is correct
7 Correct 78 ms 200 KB Output is correct
8 Correct 95 ms 200 KB Output is correct
9 Correct 80 ms 200 KB Output is correct
10 Correct 71 ms 200 KB Output is correct
11 Correct 78 ms 200 KB Output is correct
12 Correct 90 ms 200 KB Output is correct
13 Correct 70 ms 200 KB Output is correct
14 Correct 78 ms 200 KB Output is correct
15 Correct 63 ms 200 KB Output is correct
16 Correct 41 ms 200 KB Output is correct
17 Correct 68 ms 200 KB Output is correct
18 Correct 38 ms 200 KB Output is correct