답안 #501957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501957 2022-01-04T23:19:05 Z ETK Dungeon 2 (JOI16_dungeon2) C++14
100 / 100
17 ms 1504 KB
#include "dungeon2.h"
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a);i <= (b);++i)
using namespace std;
const int inf = 0x3f3f3f3f;
int d[205],T[205][205],cnt = 1,ans[205];
//1: Edges on tree, 3: Reverse of 1, 2: nontree edges
int type[205][205];
void dfs(int x){
    d[x] = NumberOfRoads();
    rep(i,1,d[x]){
        Move(i,2);
        int col = Color(),lst = LastRoad();
        type[x][i] = col;
        if(col == 1){//not visited yet
            T[x][i] = ++cnt;
            dfs(cnt);
            type[T[x][i]][lst] = 3;
            T[T[x][i]][lst] = -1;
        }else if(col == 2){
            T[x][i] = 0;
        }
        //Going back
        Move(lst,col == 1 ? 3:col);
    }
}
//用三进制分解找到非树边的编号
void work(int x,int pow3){
    rep(i,1,d[x]){
        if(type[x][i] != 3){
            Move(i,x/pow3%3+1);
            int lst = LastRoad();
            if(type[x][i] == 1)work(T[x][i],pow3);
            else T[x][i] += pow3 * (Color() - 1);
            Move(lst,Color());
        }
    }
}
void Inspect(int R){
    memset(T,-1,sizeof(T));
    dfs(1);
    int now = 1;
    rep(i,0,4){
        work(1,now);
        now *= 3;
    }
    vector <int> G[205];
    rep(i,1,cnt)rep(j,1,d[i]){
        int x = T[i][j];
        if(x != -1){
            G[i].push_back(x);
            G[x].push_back(i);
        }
    }
    queue <int> q;
    rep(i,1,cnt){
        vector <int> dis(cnt+1,inf);
        dis[i] = 0;q.push(i);
        while(!q.empty()){
            int u = q.front();q.pop();
            if(dis[u] == R)continue;
            for(auto v:G[u]){
                if(dis[v] > dis[u] + 1){
                    dis[v] = dis[u] + 1;
                    ++ans[dis[v]];
                    q.push(v);
                }
            }
        }
    }
    rep(i,1,R) Answer(i,ans[i]/2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 536 KB Output is correct
3 Correct 1 ms 580 KB Output is correct
4 Correct 1 ms 580 KB Output is correct
5 Correct 1 ms 552 KB Output is correct
6 Correct 1 ms 536 KB Output is correct
7 Correct 1 ms 544 KB Output is correct
8 Correct 1 ms 548 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 564 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 552 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 536 KB Output is correct
3 Correct 1 ms 536 KB Output is correct
4 Correct 1 ms 548 KB Output is correct
5 Correct 1 ms 560 KB Output is correct
6 Correct 1 ms 548 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 588 KB Output is correct
9 Correct 1 ms 556 KB Output is correct
10 Correct 1 ms 556 KB Output is correct
11 Correct 1 ms 540 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 548 KB Output is correct
15 Correct 1 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 972 KB Output is correct
2 Correct 2 ms 924 KB Output is correct
3 Correct 3 ms 936 KB Output is correct
4 Correct 17 ms 1476 KB Output is correct
5 Correct 1 ms 540 KB Output is correct
6 Correct 1 ms 800 KB Output is correct
7 Correct 1 ms 940 KB Output is correct
8 Correct 2 ms 928 KB Output is correct
9 Correct 2 ms 964 KB Output is correct
10 Correct 2 ms 928 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 2 ms 972 KB Output is correct
13 Correct 5 ms 1144 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 2 ms 972 KB Output is correct
16 Correct 3 ms 844 KB Output is correct
17 Correct 17 ms 1504 KB Output is correct
18 Correct 16 ms 1368 KB Output is correct
19 Correct 16 ms 1476 KB Output is correct