답안 #533748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533748 2022-03-07T05:44:44 Z 79brue Dungeon 2 (JOI16_dungeon2) C++14
44 / 100
10 ms 3020 KB
#include "dungeon2.h"
#include <bits/stdc++.h>

using namespace std;

int n;
int deg[40002];
int par[40002], prvNum[40002];
int idx[40002], origCnt;
int origLst[40002];
vector<int> link[40002];
bool isOriginal[40002];
int num[40002];

void dfs(int x, int parNum = -1){
    prvNum[x] = LastRoad();
    deg[x] = NumberOfRoads();

    if(Color() == 2){ /// 이미 방문한 정점
        Move(LastRoad(), 2);
        return;
    }

    isOriginal[x] = 1;
    idx[x] = ++origCnt;
    origLst[origCnt] = x;

    for(int i=1; i<=deg[x]; i++){
        if(i == prvNum[x]){
            par[x] = parNum;
            link[x].push_back(parNum);
            continue;
        }
        Move(i, 2);
        link[x].push_back(++n);
        dfs(n, x);
    }
    if(prvNum[x] > 0) Move(prvNum[x], 2);
}

int getBit(int x, int y){
    while(y--) x/=3;
    return x%3+1;
}

int pow3[] = {1, 3, 9, 27, 81, 243};

void dfs2(int x, int bit){
    if(isOriginal[x]){ /// 고유한 정점
        num[x] = x;
        for(int i=1; i<=deg[x]; i++){
            if(i==prvNum[x]) continue;
            Move(i, getBit(idx[x], bit));
            dfs2(link[x][i], bit);
        }
        if(prvNum[x] > 0) Move(prvNum[x], 2);
    }
    else{
        num[x] += (Color() - 1) * pow3[bit];
        Move(LastRoad(), Color());
    }
}

int dist[202][202];
int ans[202];

void Inspect(int R){
    for(int i=0; i<=40000; i++) link[i].push_back(0);
    dfs(++n);
    for(int i=0; i<6; i++){
        dfs2(1, i);
    }

    for(int i=0; i<=200; i++) for(int j=0; j<=200; j++) if(i!=j) dist[i][j] = 1e9;

    for(int i=1; i<=origCnt; i++){
        for(auto y: link[origLst[i]]){
            dist[i][isOriginal[y] ? idx[y] : num[y]] = 1;
            dist[isOriginal[y] ? idx[y] : num[y]][i] = 1;
        }
    }

    for(int k=1; k<=origCnt; k++){
        for(int i=1; i<=origCnt; i++){
            for(int j=1; j<=origCnt; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    for(int i=1; i<=origCnt; i++) for(int j=i+1; j<=origCnt; j++) ans[dist[i][j]]++;
    for(int i=1; i<=R; i++) Answer(i, ans[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 3 ms 2764 KB Output is correct
3 Correct 3 ms 2764 KB Output is correct
4 Correct 3 ms 2764 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 3 ms 2764 KB Output is correct
8 Correct 3 ms 2764 KB Output is correct
9 Correct 3 ms 2764 KB Output is correct
10 Correct 3 ms 2764 KB Output is correct
11 Correct 3 ms 2764 KB Output is correct
12 Correct 3 ms 2764 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 3 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2764 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 3 ms 2764 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 3 ms 2764 KB Output is correct
7 Correct 3 ms 2672 KB Output is correct
8 Correct 3 ms 2764 KB Output is correct
9 Correct 3 ms 2764 KB Output is correct
10 Correct 3 ms 2744 KB Output is correct
11 Correct 3 ms 2676 KB Output is correct
12 Correct 3 ms 2764 KB Output is correct
13 Correct 3 ms 2764 KB Output is correct
14 Correct 3 ms 2764 KB Output is correct
15 Correct 3 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 3020 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -