답안 #224541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224541 2020-04-18T11:03:09 Z jhnah917 저장 (Saveit) (IOI10_saveit) C++14
75 / 100
246 ms 11760 KB
#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;

int dst[44][1010];
vector<int> g[1010];
int par[1010];
int vis[1010];

void dfs(int v = 1){
    vis[v] = 1;
    for(auto i : g[v]) if(!vis[i]){
        par[i] = v; dfs(i);
    }
}

void bfs(int st){
    dst[st][st] = 0;
    queue<int> q; q.push(st);
    while(q.size()){
        int now = q.front(); q.pop();
        for(auto nxt : g[now]) if(dst[st][nxt] == -1){
            dst[st][nxt] = dst[st][now] + 1;
            q.push(nxt);
        }
    }
}

void encode(int N, int H, int M, int *v1, int *v2){
    int n = N, m = M, h = H;
    for(int i=0; i<m; i++){
        int s = v1[i] + 1, e = v2[i] + 1;
        g[s].push_back(e); g[e].push_back(s);
    }
    dfs();
    for(int i=2; i<=n; i++){
        for(int k=0; k<10; k++) encode_bit(!!(par[i] & (1 << k)));
    }
    memset(dst, -1, sizeof dst);
    for(int i=1; i<=h; i++) bfs(i);

    vector<int> v;
    for(int i=1; i<=h; i++) for(int j=2; j<=n; j++){
        int t = dst[i][j] - dst[i][par[j]];
        if(t == 1) encode_bit(0);
        else if(t == -1) encode_bit(1), encode_bit(1);
        else encode_bit(1), encode_bit(0);
        //v.push_back(dst[i][j] - dst[i][par[j]] + 1);
    }
}

//g++ grader.h grader.cpp encoder.h encoder.cpp decoder.h decoder.cpp -o main -std=c++14
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;

/*
dst[i][j] - dst[i][par[j]]
1 : 0
-1 : 11
0 : 10
*/

int p[1010];
int mm[44][1010];
int chk[1010];
int ans[44][1010];

void go(int hh, int v){
    if(v == 1) return;
    if(!chk[p[v]]) go(hh, p[v]);
    ans[hh][v] = ans[hh][p[v]] + mm[hh][v];
    chk[v] = 1;
}

void decode(int N, int H) {
    int n = N, h = H;
    for(int i=2; i<=n; i++){
        for(int j=0; j<10; j++) p[i] += (decode_bit() << j);
    }
    for(int i=1; i<=h; i++) for(int j=2; j<=n; j++){
        int a = decode_bit();
        if(!a){ mm[i][j] = 1; continue; }
        int b = decode_bit();
        if(b) mm[i][j] = -1;
        else mm[i][j] = 0;
    }
    for(int i=1; i<=h; i++){
        memset(chk, 0, sizeof chk);
        chk[1] = 1;
        for(int j=2; j<=n; j++) go(i, j);
    }
    for(int i=1; i<=h; i++) for(int j=1; j<=n; j++) hops(i-1, j-1, ans[i][j] - ans[i][i]);
}

//g++ grader.h grader.cpp encoder.h encoder.cpp decoder.h decoder.cpp -o main -std=c++14
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 11760 KB Output is partially correct - 72945 call(s) of encode_bit()
2 Correct 11 ms 5000 KB Output is correct - 58 call(s) of encode_bit()
3 Correct 33 ms 5896 KB Output is correct - 63775 call(s) of encode_bit()
4 Correct 10 ms 4864 KB Output is correct - 74 call(s) of encode_bit()
5 Correct 35 ms 6152 KB Output is correct - 65699 call(s) of encode_bit()
6 Correct 38 ms 6304 KB Output is partially correct - 73758 call(s) of encode_bit()
7 Correct 53 ms 6528 KB Output is partially correct - 78755 call(s) of encode_bit()
8 Correct 32 ms 6108 KB Output is correct - 61099 call(s) of encode_bit()
9 Correct 32 ms 5964 KB Output is correct - 50666 call(s) of encode_bit()
10 Correct 42 ms 5832 KB Output is correct - 50096 call(s) of encode_bit()
11 Correct 38 ms 6144 KB Output is correct - 53294 call(s) of encode_bit()
12 Correct 35 ms 5888 KB Output is correct - 55631 call(s) of encode_bit()
13 Correct 62 ms 6872 KB Output is partially correct - 72891 call(s) of encode_bit()
14 Correct 39 ms 5888 KB Output is correct - 62784 call(s) of encode_bit()
15 Correct 35 ms 6152 KB Output is correct - 64009 call(s) of encode_bit()
16 Correct 62 ms 6436 KB Output is correct - 64728 call(s) of encode_bit()
17 Correct 54 ms 6724 KB Output is correct - 64621 call(s) of encode_bit()
18 Correct 64 ms 6776 KB Output is correct - 68998 call(s) of encode_bit()
19 Correct 44 ms 6456 KB Output is partially correct - 71632 call(s) of encode_bit()
20 Correct 75 ms 7160 KB Output is partially correct - 74650 call(s) of encode_bit()
21 Correct 81 ms 7288 KB Output is partially correct - 72823 call(s) of encode_bit()
22 Correct 59 ms 6776 KB Output is partially correct - 76495 call(s) of encode_bit()
23 Correct 87 ms 7428 KB Output is partially correct - 75469 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 11760 KB Output is partially correct - 72945 call(s) of encode_bit()
2 Correct 11 ms 5000 KB Output is correct - 58 call(s) of encode_bit()
3 Correct 33 ms 5896 KB Output is correct - 63775 call(s) of encode_bit()
4 Correct 10 ms 4864 KB Output is correct - 74 call(s) of encode_bit()
5 Correct 35 ms 6152 KB Output is correct - 65699 call(s) of encode_bit()
6 Correct 38 ms 6304 KB Output is partially correct - 73758 call(s) of encode_bit()
7 Correct 53 ms 6528 KB Output is partially correct - 78755 call(s) of encode_bit()
8 Correct 32 ms 6108 KB Output is correct - 61099 call(s) of encode_bit()
9 Correct 32 ms 5964 KB Output is correct - 50666 call(s) of encode_bit()
10 Correct 42 ms 5832 KB Output is correct - 50096 call(s) of encode_bit()
11 Correct 38 ms 6144 KB Output is correct - 53294 call(s) of encode_bit()
12 Correct 35 ms 5888 KB Output is correct - 55631 call(s) of encode_bit()
13 Correct 62 ms 6872 KB Output is partially correct - 72891 call(s) of encode_bit()
14 Correct 39 ms 5888 KB Output is correct - 62784 call(s) of encode_bit()
15 Correct 35 ms 6152 KB Output is correct - 64009 call(s) of encode_bit()
16 Correct 62 ms 6436 KB Output is correct - 64728 call(s) of encode_bit()
17 Correct 54 ms 6724 KB Output is correct - 64621 call(s) of encode_bit()
18 Correct 64 ms 6776 KB Output is correct - 68998 call(s) of encode_bit()
19 Correct 44 ms 6456 KB Output is partially correct - 71632 call(s) of encode_bit()
20 Correct 75 ms 7160 KB Output is partially correct - 74650 call(s) of encode_bit()
21 Correct 81 ms 7288 KB Output is partially correct - 72823 call(s) of encode_bit()
22 Correct 59 ms 6776 KB Output is partially correct - 76495 call(s) of encode_bit()
23 Correct 87 ms 7428 KB Output is partially correct - 75469 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 11760 KB Output is partially correct - 72945 call(s) of encode_bit()
2 Correct 11 ms 5000 KB Output is correct - 58 call(s) of encode_bit()
3 Correct 33 ms 5896 KB Output is correct - 63775 call(s) of encode_bit()
4 Correct 10 ms 4864 KB Output is correct - 74 call(s) of encode_bit()
5 Correct 35 ms 6152 KB Output is correct - 65699 call(s) of encode_bit()
6 Correct 38 ms 6304 KB Output is partially correct - 73758 call(s) of encode_bit()
7 Correct 53 ms 6528 KB Output is partially correct - 78755 call(s) of encode_bit()
8 Correct 32 ms 6108 KB Output is correct - 61099 call(s) of encode_bit()
9 Correct 32 ms 5964 KB Output is correct - 50666 call(s) of encode_bit()
10 Correct 42 ms 5832 KB Output is correct - 50096 call(s) of encode_bit()
11 Correct 38 ms 6144 KB Output is correct - 53294 call(s) of encode_bit()
12 Correct 35 ms 5888 KB Output is correct - 55631 call(s) of encode_bit()
13 Correct 62 ms 6872 KB Output is partially correct - 72891 call(s) of encode_bit()
14 Correct 39 ms 5888 KB Output is correct - 62784 call(s) of encode_bit()
15 Correct 35 ms 6152 KB Output is correct - 64009 call(s) of encode_bit()
16 Correct 62 ms 6436 KB Output is correct - 64728 call(s) of encode_bit()
17 Correct 54 ms 6724 KB Output is correct - 64621 call(s) of encode_bit()
18 Correct 64 ms 6776 KB Output is correct - 68998 call(s) of encode_bit()
19 Correct 44 ms 6456 KB Output is partially correct - 71632 call(s) of encode_bit()
20 Correct 75 ms 7160 KB Output is partially correct - 74650 call(s) of encode_bit()
21 Correct 81 ms 7288 KB Output is partially correct - 72823 call(s) of encode_bit()
22 Correct 59 ms 6776 KB Output is partially correct - 76495 call(s) of encode_bit()
23 Correct 87 ms 7428 KB Output is partially correct - 75469 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 11760 KB Output is partially correct - 72945 call(s) of encode_bit()
2 Correct 11 ms 5000 KB Output is correct - 58 call(s) of encode_bit()
3 Correct 33 ms 5896 KB Output is correct - 63775 call(s) of encode_bit()
4 Correct 10 ms 4864 KB Output is correct - 74 call(s) of encode_bit()
5 Correct 35 ms 6152 KB Output is correct - 65699 call(s) of encode_bit()
6 Correct 38 ms 6304 KB Output is partially correct - 73758 call(s) of encode_bit()
7 Correct 53 ms 6528 KB Output is partially correct - 78755 call(s) of encode_bit()
8 Correct 32 ms 6108 KB Output is correct - 61099 call(s) of encode_bit()
9 Correct 32 ms 5964 KB Output is correct - 50666 call(s) of encode_bit()
10 Correct 42 ms 5832 KB Output is correct - 50096 call(s) of encode_bit()
11 Correct 38 ms 6144 KB Output is correct - 53294 call(s) of encode_bit()
12 Correct 35 ms 5888 KB Output is correct - 55631 call(s) of encode_bit()
13 Correct 62 ms 6872 KB Output is partially correct - 72891 call(s) of encode_bit()
14 Correct 39 ms 5888 KB Output is correct - 62784 call(s) of encode_bit()
15 Correct 35 ms 6152 KB Output is correct - 64009 call(s) of encode_bit()
16 Correct 62 ms 6436 KB Output is correct - 64728 call(s) of encode_bit()
17 Correct 54 ms 6724 KB Output is correct - 64621 call(s) of encode_bit()
18 Correct 64 ms 6776 KB Output is correct - 68998 call(s) of encode_bit()
19 Correct 44 ms 6456 KB Output is partially correct - 71632 call(s) of encode_bit()
20 Correct 75 ms 7160 KB Output is partially correct - 74650 call(s) of encode_bit()
21 Correct 81 ms 7288 KB Output is partially correct - 72823 call(s) of encode_bit()
22 Correct 59 ms 6776 KB Output is partially correct - 76495 call(s) of encode_bit()
23 Correct 87 ms 7428 KB Output is partially correct - 75469 call(s) of encode_bit()