답안 #766106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766106 2023-06-25T10:19:18 Z pandapythoner Monster Game (JOI21_monster) C++17
91 / 100
92 ms 336 KB
#include <bits/stdc++.h>

#include "monster.h"

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(2342334);

bool query(int a, int b) {
    return !Query(a, b);
}

vector<int> merge(vector<int> a, vector<int> b) {
    vector<int> c;
    int i = 0;
    int j = 0;
    while (i < (int)a.size() && j < (int)b.size()) {
        if (query(a[i], b[j])) {
            c.push_back(a[i]);
            i += 1;
        } else {
            c.push_back(b[j]);
            j += 1;
        }
    }
    while (i < (int)a.size()) {
        c.push_back(a[i]);
        i += 1;
    }
    while (j < (int)b.size()) {
        c.push_back(b[j]);
        j += 1;
    }
    return c;
}

vector<int> merge_sort(vector<int> a) {
    if (a.size() == 1) {
        return a;
    }
    int sz = (int)a.size();
    vector<int> x, y;
    for (int i = 0; i < sz; i += 1) {
        if (i < sz / 2) {
            x.push_back(a[i]);
        } else {
            y.push_back(a[i]);
        }
    }
    x = merge_sort(x);
    y = merge_sort(y);
    auto z = merge(x, y);
    return z;
}

vector<int> Solve(int n) {
    vector<int> t(n);
    for (int i = 0; i < n; i += 1) {
        t[i] = i;
    }
    shuffle(all(t), rnd);
    t = merge_sort(t);
    if (query(t[0], t[n - 1])) {
        int x = -1;
        for (int i = n - 2; i >= 0; i -= 1) {
            if (!query(t[0], t[i])) {
                x = i;
                break;
            }
        }
        if (x == -1) {
            assert(0);
        }
        if (x == 1) {
            assert(0);
        }
        int fuck = -1;
        if (x == 2) {
            bool is_1_mx = false;
            for (int i = 3; i < n; i += 1) {
                if (!query(t[1], t[i])) {
                    is_1_mx = true;
                    break;
                }
            }
            if (is_1_mx) {
                swap(t[1], t[2]);
                fuck = x + 1;
            } else {
                swap(t[0], t[1]);
                fuck = x + 1;
            }
        } else {
            int m = x + 1;
            vector<int> q(m - 2);
            for (int i = 0; i < m - 2; i += 1) {
                q[i] = query(t[i], t[i + 2]);
            }
            int d = -1;
            for (int i = 0; i + 1 < m - 2; i += 1) {
                if (q[i] && q[i + 1]) {
                    d = i + 1;
                    break;
                }
            }
            if (d == -1) {
                if (q[0]) {
                    d = 0;
                } else if (q[m - 3]) {
                    d = m - 2;
                }
            }
            if (d == -1) {
                assert(0);
            } else {
                reverse(t.begin(), t.begin() + d + 1);
                reverse(t.begin() + d + 1, t.begin() + m);
            }
            fuck = m;
        }
        while (fuck < n) {
            int new_fuck = -1;
            for (int i = fuck; i < n; i += 1) {
                if (!query(t[fuck - 1], t[i])) {
                    new_fuck = i + 1;
                    break;
                }
            }
            if (new_fuck == -1) {
                assert(0);
            }
            reverse(t.begin() + fuck, t.begin() + new_fuck);
            fuck = new_fuck;
        }
    } else {
        vector<int> q(n - 2);
        for (int i = 0; i < n - 2; i += 1) {
            q[i] = query(t[i], t[i + 2]);
        }
        int d = -1;
        for (int i = 0; i + 1 < n - 2; i += 1) {
            if (q[i] && q[i + 1]) {
                d = i + 1;
                break;
            }
        }
        if (d == -1) {
            if (q[0]) {
                d = 0;
            } else if (q[n - 3]) {
                d = n - 2;
            }
        }
        if (d == -1) {
            reverse(all(t));
        } else {
            reverse(t.begin(), t.begin() + d + 1);
            reverse(t.begin() + d + 1, t.end());
        }
    }
    vector<int> p(n);
    for (int i = 0; i < n; i += 1) {
        p[t[i]] = i;
    }
    return p;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 12 ms 304 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 15 ms 312 KB Output is correct
19 Correct 11 ms 208 KB Output is correct
20 Correct 14 ms 308 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 12 ms 308 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 0 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 15 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 12 ms 304 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 15 ms 312 KB Output is correct
19 Correct 11 ms 208 KB Output is correct
20 Correct 14 ms 308 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 12 ms 308 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 0 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 15 ms 208 KB Output is correct
33 Correct 91 ms 208 KB Output is correct
34 Correct 62 ms 328 KB Output is correct
35 Correct 89 ms 308 KB Output is correct
36 Correct 85 ms 308 KB Output is correct
37 Correct 55 ms 324 KB Output is correct
38 Correct 90 ms 208 KB Output is correct
39 Correct 78 ms 312 KB Output is correct
40 Correct 63 ms 324 KB Output is correct
41 Correct 82 ms 312 KB Output is correct
42 Correct 79 ms 320 KB Output is correct
43 Correct 54 ms 312 KB Output is correct
44 Correct 75 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 57 ms 324 KB Partially correct
2 Partially correct 50 ms 312 KB Partially correct
3 Partially correct 37 ms 336 KB Partially correct
4 Partially correct 88 ms 312 KB Partially correct
5 Partially correct 72 ms 328 KB Partially correct
6 Correct 86 ms 320 KB Output is correct
7 Correct 76 ms 312 KB Output is correct
8 Partially correct 65 ms 328 KB Partially correct
9 Partially correct 76 ms 208 KB Partially correct
10 Partially correct 68 ms 308 KB Partially correct
11 Partially correct 89 ms 336 KB Partially correct
12 Partially correct 92 ms 312 KB Partially correct
13 Correct 53 ms 312 KB Output is correct
14 Correct 83 ms 316 KB Output is correct
15 Correct 41 ms 312 KB Output is correct
16 Correct 48 ms 328 KB Output is correct
17 Correct 75 ms 312 KB Output is correct
18 Correct 58 ms 308 KB Output is correct