Submission #951698

# Submission time Handle Problem Language Result Execution time Memory
951698 2024-03-22T11:00:33 Z arbuzick Monster Game (JOI21_monster) C++17
25 / 100
135 ms 1764 KB
#include "monster.h"

#include <bits/stdc++.h>

using namespace std;

mt19937 rnd(57);

int get_mx(vector<int> nw) {
    int ans = nw[0];
    for (int i = 1; i < (int)nw.size(); ++i) {
        if (Query(nw[i], ans)) {
            ans = nw[i];
        }
    }
    return ans;
}

int get_mn(vector<int> nw) {
    int ans = nw[0];
    for (int i = 1; i < (int)nw.size(); ++i) {
        if (Query(ans, nw[i])) {
            ans = nw[i];
        }
    }
    return ans;
}

vector<int> my_sort(vector<int> nw) {
    if (nw.size() <= 1) {
        return nw;
    }
    if (nw.size() <= 10) {
        map<pair<int, int>, int> vl;
        map<int, int> cnt;
        for (int i = 0; i < (int)nw.size(); ++i) {
            for (int j = i + 1; j < (int)nw.size(); ++j) {
                if (Query(nw[i], nw[j])) {
                    vl[{nw[i], nw[j]}] = 1;
                    cnt[nw[i]]++;
                } else {
                    vl[{nw[j], nw[i]}] = 1;
                    cnt[nw[j]]++;
                }
            }
        }
        int start;
        for (int i = 0; i < (int)nw.size(); ++i) {
            if (cnt[nw[i]] == 1) {
                bool check = true;
                for (int j = 0; j < (int)nw.size(); ++j) {
                    if (vl[{nw[i], nw[j]}] && cnt[nw[j]] != 1) {
                        check = false;
                        break;
                    }
                }
                if (check) {
                    start = nw[i];
                    break;
                }
            }
        }
        vector<int> ans = {start};
        set<int> used = {start};
        while (ans.size() < nw.size()) {
            for (int i = 0; i < (int)nw.size(); ++i) {
                if (!used.count(nw[i]) && vl[{ans.back(), nw[i]}]) {
                    ans.push_back(nw[i]);
                    used.insert(nw[i]);
                    break;
                }
            }
        }
        return ans;
    }
    vector<int> ord_check = nw;
    shuffle(ord_check.begin(), ord_check.end(), rnd);
    for (auto val_md : ord_check) {
        vector<int> l, r;
        for (int i = 0; i < (int)nw.size(); ++i) {
            if (nw[i] == val_md) {
                continue;
            }
            if (Query(val_md, nw[i])) {
                l.push_back(nw[i]);
            } else {
                r.push_back(nw[i]);
            }
        }
        if (l.size() <= 3 || r.size() <= 3) {
            continue;
        }
        int l_mx = get_mx(l), r_mn = get_mn(r);
        vector<int> ll, rr;
        for (auto vl : l) {
            if (vl != l_mx) {
                ll.push_back(vl);
            }
        }
        ll.push_back(r_mn);
        for (auto vl : r) {
            if (vl != r_mn) {
                rr.push_back(vl);
            }
        }
        rr.push_back(l_mx);
        ll = my_sort(ll);
        rr = my_sort(rr);
        vector<int> ans = ll;
        // ans.push_back(r_mn);
        ans.push_back(val_md);
        // ans.push_back(l_mx);
        for (auto vl : rr) {
            ans.push_back(vl);
        }
        return ans;
    }
    exit(1);
}

vector<int> Solve(int n) {
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    shuffle(ord.begin(), ord.end(), rnd);
    for (int i = 0; i + 1 < n; i += 2) {
        Query(ord[i], ord[i + 1]);
    }
    ord = my_sort(ord);
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        ans[ord[i]] = i;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 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 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 11 ms 600 KB Output is correct
17 Correct 13 ms 1112 KB Output is correct
18 Correct 13 ms 856 KB Output is correct
19 Correct 12 ms 1116 KB Output is correct
20 Correct 11 ms 1100 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 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 11 ms 860 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 11 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 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 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 11 ms 600 KB Output is correct
17 Correct 13 ms 1112 KB Output is correct
18 Correct 13 ms 856 KB Output is correct
19 Correct 12 ms 1116 KB Output is correct
20 Correct 11 ms 1100 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 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 11 ms 860 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 11 ms 1116 KB Output is correct
33 Correct 111 ms 1476 KB Output is correct
34 Correct 130 ms 1120 KB Output is correct
35 Correct 86 ms 1368 KB Output is correct
36 Correct 110 ms 952 KB Output is correct
37 Correct 102 ms 1236 KB Output is correct
38 Correct 117 ms 1420 KB Output is correct
39 Correct 101 ms 960 KB Output is correct
40 Correct 97 ms 1436 KB Output is correct
41 Correct 119 ms 1260 KB Output is correct
42 Correct 91 ms 1232 KB Output is correct
43 Correct 135 ms 1112 KB Output is correct
44 Correct 102 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 104 ms 1128 KB Partially correct
2 Partially correct 106 ms 1216 KB Partially correct
3 Partially correct 86 ms 1220 KB Partially correct
4 Partially correct 97 ms 1236 KB Partially correct
5 Partially correct 80 ms 1004 KB Partially correct
6 Partially correct 105 ms 1764 KB Partially correct
7 Partially correct 101 ms 1256 KB Partially correct
8 Partially correct 89 ms 1472 KB Partially correct
9 Partially correct 95 ms 1212 KB Partially correct
10 Partially correct 87 ms 964 KB Partially correct
11 Partially correct 110 ms 1232 KB Partially correct
12 Partially correct 83 ms 1368 KB Partially correct
13 Incorrect 124 ms 1236 KB Wrong Answer [6]
14 Halted 0 ms 0 KB -