Submission #423533

# Submission time Handle Problem Language Result Execution time Memory
423533 2021-06-11T08:58:10 Z 최서현(#7497) Monster Game (JOI21_monster) C++17
93 / 100
146 ms 1084 KB
#include "monster.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <tuple>
#include <map>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG
const int INF = (int)1e9 + 7;

using namespace std;

namespace {
    vector<int> ret;
    map<pii, int> M;
    bool Q(int x, int y)
    {
        if(M.count({x, y})) return M[{x, y}];
        if(M.count({y, x})) return !M[{y, x}];
        return M[{x, y}] = Query(x, y);
    }
    void f(int s, int e)
    {
        if(s + 1 == e) return;
        int mid = s + e >> 1;
        f(s, mid);
        f(mid, e);
        int pt = 0, pt1 = s, pt2 = mid;
        int tmp[e - s];
        while(pt1 < mid && pt2 < e)
        {
            if(Q(ret[pt1], ret[pt2])) tmp[pt++] = ret[pt2++];
            else tmp[pt++] = ret[pt1++];
        }
        while(pt1 < mid) tmp[pt++] = ret[pt1++];
        while(pt2 < e) tmp[pt++] = ret[pt2++];
        for(int i = s; i < e; ++i) ret[i] = tmp[i - s];
    }
}

vector<int> Solve(int N)
{
    ret.resize(N);
    for(int i = 0; i < N; ++i) ret[i] = i;

    f(0, N);

    int cnt = 0, pr = 0;;
    for(int i = 1; i < N; ++i) if(Q(ret[0], ret[i])) ++cnt;
    if(cnt == 1)
    {
        int cnt2 = 0;
        for(int i = 2; i < N; ++i) if(Q(ret[1], ret[i])) ++cnt2;
        if(cnt2 == 0)
        {
            swap(ret[0], ret[1]);
            pr = 1;
        }
        else
        {
            pr = 0;
        }
    }
    else
    {
        reverse(ret.begin(), ret.begin() + cnt + 1);
        pr = cnt;
    }
    for(int i = pr + 1; i < N; ++i)
    {
        if(Q(ret[pr], ret[i]))
        {
            reverse(ret.begin() + pr + 1, ret.begin() + i + 1);
            pr = i;
        }
    }

    vector<int> rret(N);
    for(int i = 0; i < N; ++i) rret[ret[i]] = i;

//    for(auto i : ret) cout << i << ' '; cout << endl;
    return rret;
}

Compilation message

monster.cpp: In function 'bool {anonymous}::Q(int, int)':
monster.cpp:30:26: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   30 |         return M[{x, y}] = Query(x, y);
monster.cpp: In function 'void {anonymous}::f(int, int)':
monster.cpp:35:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |         int mid = s + e >> 1;
      |                   ~~^~~
# Verdict Execution time Memory 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 2 ms 200 KB Output is correct
16 Correct 17 ms 352 KB Output is correct
17 Correct 27 ms 340 KB Output is correct
18 Correct 28 ms 324 KB Output is correct
19 Correct 14 ms 332 KB Output is correct
20 Correct 17 ms 380 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 16 ms 340 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 1 ms 200 KB Output is correct
32 Correct 6 ms 328 KB Output is correct
# Verdict Execution time Memory 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 2 ms 200 KB Output is correct
16 Correct 17 ms 352 KB Output is correct
17 Correct 27 ms 340 KB Output is correct
18 Correct 28 ms 324 KB Output is correct
19 Correct 14 ms 332 KB Output is correct
20 Correct 17 ms 380 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 16 ms 340 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 1 ms 200 KB Output is correct
32 Correct 6 ms 328 KB Output is correct
33 Correct 90 ms 1032 KB Output is correct
34 Correct 120 ms 980 KB Output is correct
35 Correct 93 ms 816 KB Output is correct
36 Correct 92 ms 1084 KB Output is correct
37 Correct 139 ms 1028 KB Output is correct
38 Correct 69 ms 840 KB Output is correct
39 Correct 145 ms 996 KB Output is correct
40 Correct 124 ms 904 KB Output is correct
41 Correct 137 ms 976 KB Output is correct
42 Correct 122 ms 984 KB Output is correct
43 Correct 90 ms 644 KB Output is correct
44 Correct 102 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 119 ms 1064 KB Partially correct
2 Partially correct 114 ms 1004 KB Partially correct
3 Partially correct 124 ms 928 KB Partially correct
4 Partially correct 128 ms 884 KB Partially correct
5 Partially correct 108 ms 964 KB Partially correct
6 Correct 131 ms 900 KB Output is correct
7 Correct 90 ms 784 KB Output is correct
8 Partially correct 77 ms 960 KB Partially correct
9 Partially correct 128 ms 820 KB Partially correct
10 Partially correct 126 ms 948 KB Partially correct
11 Partially correct 146 ms 968 KB Partially correct
12 Partially correct 86 ms 900 KB Partially correct
13 Correct 105 ms 828 KB Output is correct
14 Correct 117 ms 848 KB Output is correct
15 Correct 56 ms 636 KB Output is correct
16 Correct 72 ms 688 KB Output is correct
17 Partially correct 134 ms 832 KB Partially correct
18 Correct 67 ms 628 KB Output is correct