답안 #895681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895681 2023-12-30T14:00:52 Z Alcabel Monster Game (JOI21_monster) C++17
94 / 100
51 ms 852 KB
#include <bits/stdc++.h>
#include "monster.h"
using namespace std;

void sort(int l, int r, vector<int>& order) {
    if (l + 1 >= r) {
        return;
    }
    int m = l + (r - l) / 2;
    sort(l, m, order);
    sort(m, r, order);
    vector<int> tmp(r - l);
    int ptrL = l, ptrR = m, ptr = 0;
    while (ptrL < m && ptrR < r) {
        if (Query(order[ptrR], order[ptrL])) {
            tmp[ptr++] = order[ptrL++];
        } else {
            tmp[ptr++] = order[ptrR++];
        }
    }
    while (ptrL < m) {
        tmp[ptr++] = order[ptrL++];
    }
    while (ptrR < r) {
        tmp[ptr++] = order[ptrR++];
    }
    for (int i = 0; i < r - l; ++i) {
        order[l + i] = tmp[i];
    }
}

vector<int> Solve(int n) {
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(0, n, order);
    int cntWin = 0, firstWin = n, firstLoss = n;
    for (int i = 1; i < n; ++i) {
        if (Query(order[0], order[i])) {
            ++cntWin;
            firstWin = min(i, firstWin);
        } else {
            firstLoss = min(i, firstLoss);
        }
    }
    int border = -1;
    if (cntWin > 1 && cntWin < n - 2) {
        // order[cntWin] = 0;
        border = cntWin + 1;
    } else if (cntWin == 1) {
        // order[0] = 1 or 0
        if (firstWin == 1) {
            border = 1;
        } else {
            if (firstWin >= 3) {
                if (Query(order[firstWin], order[1])) {
                    border = 2;
                } else {
                    border = 1;
                }
            } else {
                bool moreWon = false;
                vector<int> rask(n - 3);
                iota(rask.begin(), rask.end(), 3);
                mt19937 rnd(161);
                shuffle(rask.begin(), rask.end(), rnd);
                for (const int& i : rask) {
                    if (Query(order[2], order[i])) {
                        moreWon = true;
                        break;
                    }
                }
                if (moreWon) {
                    border = 2;
                } else {
                    border = 1;
                }
            }
        }
    } else {
        // order[0] = n - 1 or n - 2
        if (Query(order[n - 3], order[n - 1])) {
            border = n;
        } else {
            border = n - 1;
        }
    }
    reverse(order.begin(), order.begin() + border);
    while (border < n - 1) {
        int newBorder = border;
        while (!Query(order[border - 1], order[newBorder])) {
            ++newBorder;
        }
        reverse(order.begin() + border, order.begin() + newBorder + 1);
        border = newBorder + 1;
    }
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        ans[order[i]] = i;
    }
    return ans;
}
/*
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        cerr << "-----------\n";
        cout << "-----------\n";
    }
#else
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
#endif

    return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 8 ms 440 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 596 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 8 ms 440 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 596 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
33 Correct 46 ms 600 KB Output is correct
34 Correct 43 ms 600 KB Output is correct
35 Correct 40 ms 600 KB Output is correct
36 Correct 47 ms 600 KB Output is correct
37 Correct 40 ms 440 KB Output is correct
38 Correct 49 ms 444 KB Output is correct
39 Correct 44 ms 600 KB Output is correct
40 Correct 51 ms 600 KB Output is correct
41 Correct 47 ms 600 KB Output is correct
42 Correct 50 ms 436 KB Output is correct
43 Correct 29 ms 592 KB Output is correct
44 Correct 26 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 39 ms 672 KB Partially correct
2 Partially correct 41 ms 600 KB Partially correct
3 Partially correct 42 ms 600 KB Partially correct
4 Partially correct 47 ms 600 KB Partially correct
5 Partially correct 48 ms 676 KB Partially correct
6 Correct 38 ms 676 KB Output is correct
7 Partially correct 43 ms 600 KB Partially correct
8 Partially correct 49 ms 440 KB Partially correct
9 Partially correct 40 ms 680 KB Partially correct
10 Partially correct 41 ms 420 KB Partially correct
11 Partially correct 51 ms 592 KB Partially correct
12 Partially correct 49 ms 432 KB Partially correct
13 Correct 37 ms 600 KB Output is correct
14 Partially correct 36 ms 448 KB Partially correct
15 Correct 27 ms 600 KB Output is correct
16 Correct 29 ms 444 KB Output is correct
17 Correct 43 ms 676 KB Output is correct
18 Correct 33 ms 852 KB Output is correct