답안 #1069835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069835 2024-08-22T09:18:54 Z juicy Dungeon 2 (JOI16_dungeon2) C++17
100 / 100
13 ms 1252 KB
#include "dungeon2.h"

#include <bits/stdc++.h>

using namespace std;

namespace {
    const int N = 200, LG = 5;

    int n;
    int d[N][N], deg[N], res[N], pr[N];
    vector<array<int, 2>> tree[N], back[N];

    void init() {
        int u = n++;
        deg[u] = NumberOfRoads();
        for (int i = 1; i <= deg[u]; ++i) {
            if (i == pr[u]) {
                continue;
            }
            Move(i, 2);
            int c = Color();
            int ind = LastRoad();
            if (c == 1) {
                pr[n] = ind;
                tree[u].push_back({n, i});
                init();
                Move(ind, 3);
            } else if (c == 2) {
                back[u].push_back({i, 0});
                Move(ind, 2);
            } else {
                Move(ind, 3);
            }
        }
    }

    void dfs(int u, int x) {
        int c = (u / x) % 3 + 1;
        for (auto &[v, ind] : back[u]) {
            Move(v, c);
            int w = Color();
            ind += (w - 1) * x;
            Move(LastRoad(), w);
        }
        for (auto [v, ind] : tree[u]) {
            Move(ind, c);
            int i = LastRoad();
            dfs(v, x);
            Move(i, 3);
        }
    }
}

void Inspect(int R) {
    init();
    for (int i = 1, j = 0; j < LG; i *= 3, ++j) {
        dfs(0, i);
    }
    for (int i = 0; i < n; ++i) {
        fill(d[i], d[i] + n, N + 1);
        d[i][i] = 0;
    }
    for (int i = 0; i < n; ++i) {
        for (auto [j, ind] : tree[i]) {
            d[i][j] = d[j][i] = 1;
        }
        for (auto [ind, j] : back[i]) {
            d[i][j] = d[j][i] = 1;
        }
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (d[i][j] <= R) {
                ++res[d[i][j] - 1];
            }
        }
    }
    for (int i = 1; i <= R; ++i) {
        Answer(i, res[i - 1]);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 520 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 860 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
3 Correct 7 ms 1028 KB Output is correct
4 Correct 12 ms 1252 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 7 ms 860 KB Output is correct
8 Correct 7 ms 1020 KB Output is correct
9 Correct 7 ms 860 KB Output is correct
10 Correct 12 ms 860 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 7 ms 1064 KB Output is correct
14 Correct 6 ms 860 KB Output is correct
15 Correct 7 ms 860 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 12 ms 1116 KB Output is correct
18 Correct 13 ms 1116 KB Output is correct
19 Correct 12 ms 1116 KB Output is correct