답안 #833211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833211 2023-08-22T03:14:50 Z maomao90 Monster Game (JOI21_monster) C++17
64 / 100
105 ms 300 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
#include "monster.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 1005;


namespace {
    int n;
    vi p, op;
    int tmp[MAXN];
    bool res[MAXN];
    void dnc(int l, int r) {
        if (l == r) {
            return;
        }
        int m = l + r >> 1;
        dnc(l, m); dnc(m + 1, r);
        int pl = l, pr = m + 1;
        int ptr = l;
        while (pl <= m || pr <= r) {
            if (pr > r || (pl <= m && !Query(p[pl], p[pr]))) {
                tmp[ptr++] = p[pl++];
            } else {
                tmp[ptr++] = p[pr++];
            }
        }
        REP (i, l, r + 1) {
            p[i] = tmp[i];
        }
    }
}

vi Solve(int N) {
    n = N;
    p = vi(n);
    iota(ALL(p), 0);
    dnc(0, n - 1);
    op = p;
    REP (i, 0, n) {
        cerr << p[i] << ' ';
    }
    cerr << '\n';
    bool pos = 1;
    REP (i, 0, n - 1) {
        if (Query(p[i], p[i + 1])) {
            continue;
        }
        int id = -1;
        REP (j, i + 1, n) {
            if (Query(p[i], p[j])) {
                id = j;
                break;
            }
        }
        if (id == -1) {
            pos = 0;
            break;
        }
        /*
        if (i == 0 && id == 2) {
            REP (j, 3, n) {
                if (!Query(p[0], p[j])) {
                    id = j;
                    break;
                }
            }
            if (id == 3) {
                bool gd = 0;
                REP (j, 3, n) {
                    if (Query(p[1], p[j])) {
                        gd = 1;
                        break;
                    }
                }
                if (gd) {
                    swap(p[1], p[2]);
                } else {
                    swap(p[0], p[2]);
                }
                i = 1;
                continue;
            }
            if (Query(p[id - 2], p[id - 1])) {
                id--;
            } else {
                id -= 2;
            }
        }
        */
        reverse(p.begin() + i + 1, p.begin() + id + 1);
        i = id - 1;
    }
    if (pos) {
        REP (i, 0, n - 1) {
            if (!Query(p[i], p[i + 1])) {
                pos = 0;
                break;
            }
        }
    }
    /*
    if (pos) {
        REP (i, 0, n - 2) {
            if (Query(p[i], p[i + 2])) {
                pos = 0;
                break;
            }
        }
    }
    */
    if (pos) {
        REP (i, 0, n) {
            cerr << p[i] << ' ';
        }
        cerr << '\n';
        vi t(n);
        REP (i, 0, n) {
            t[p[i]] = i;
        }
        return t;
    }
    p = op;
    REP (i, 1, n) {
        res[i] = Query(p[0], p[i]);
    }
    assert(res[1] == 0);
    int prv = 1;
    vi v;
    REP (i, 2, n) {
        if (res[i] != res[i - 1]) {
            v.pb(prv);
            prv = i;
        }
    }
    v.pb(prv);
    assert(SZ(v) >= 2);
    if (SZ(v) >= 4) {
        reverse(p.begin(), p.begin() + v[2]);
    } else if ((SZ(v) == 2 ? n : v[2]) - v[1] == 1) {
        swap(p[0], p[1]);
    } else {
        reverse(p.begin(), p.begin() + v[2] - 1);
    }
    REP (i, 0, n - 1) {
        if (Query(p[i], p[i + 1])) {
            continue;
        }
        int id = -1;
        REP (j, i + 1, n) {
            if (Query(p[i], p[j])) {
                id = j;
                break;
            }
        }
        assert(id != -1);
        reverse(p.begin() + i + 1, p.begin() + id + 1);
        i = id - 1;
    }
    vi t(n);
    REP (i, 0, n) {
        t[p[i]] = i;
    }
    return t;
}

Compilation message

monster.cpp: In function 'void {anonymous}::dnc(int, int)':
monster.cpp:51:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |         int m = l + r >> 1;
      |                 ~~^~~
# 결과 실행 시간 메모리 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 0 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 1 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 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 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 1 ms 208 KB Output is correct
16 Correct 16 ms 208 KB Output is correct
17 Correct 17 ms 208 KB Output is correct
18 Correct 10 ms 208 KB Output is correct
19 Correct 16 ms 296 KB Output is correct
20 Correct 11 ms 208 KB Output is correct
21 Incorrect 0 ms 208 KB Wrong Answer [3]
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 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 1 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 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 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 1 ms 208 KB Output is correct
16 Correct 16 ms 208 KB Output is correct
17 Correct 17 ms 208 KB Output is correct
18 Correct 10 ms 208 KB Output is correct
19 Correct 16 ms 296 KB Output is correct
20 Correct 11 ms 208 KB Output is correct
21 Incorrect 0 ms 208 KB Wrong Answer [3]
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 57 ms 292 KB Partially correct
2 Partially correct 71 ms 208 KB Partially correct
3 Partially correct 71 ms 288 KB Partially correct
4 Partially correct 58 ms 284 KB Partially correct
5 Partially correct 68 ms 292 KB Partially correct
6 Partially correct 77 ms 292 KB Partially correct
7 Partially correct 80 ms 292 KB Partially correct
8 Partially correct 105 ms 284 KB Partially correct
9 Partially correct 103 ms 300 KB Partially correct
10 Partially correct 76 ms 288 KB Partially correct
11 Partially correct 103 ms 296 KB Partially correct
12 Partially correct 97 ms 288 KB Partially correct
13 Partially correct 85 ms 292 KB Partially correct
14 Partially correct 81 ms 296 KB Partially correct
15 Correct 70 ms 292 KB Output is correct
16 Correct 43 ms 292 KB Output is correct
17 Partially correct 77 ms 292 KB Partially correct
18 Correct 64 ms 288 KB Output is correct