답안 #271306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
271306 2020-08-18T05:35:54 Z 반딧불(#5113) 저장 (Saveit) (IOI10_saveit) C++14
100 / 100
275 ms 11776 KB
#include <bits/stdc++.h>
#include "grader.h"
#include "encoder.h"

using namespace std;

namespace{
    int n, k, m;
    vector<int> link[1002];
    int dist[40][1002];
    int par[1002];

    void makeTree(int x, int p = 1004){
        par[x] = p;
        for(auto &y: link[x]){
            if(par[y] != 1004 || y==0) continue;
            makeTree(y, x);
        }
    }

    void bfs(int h){
        bool visited[1002] = {0};
        queue<pair<int, int> > que;
        que.push({h, 0});
        visited[h] = 1;

        while(!que.empty()){
            pair<int, int> tmp = que.front();
            int x = tmp.first, d = tmp.second;
            que.pop();
            for(auto &y: link[x]){
                if(visited[y]) continue;
                visited[y] = 1;
                dist[h][y] = d+1;
                que.push({y, d+1});
            }
        }
    }
}

void encode(int N, int K, int M, int *U, int *V){
    n = N, k = K, m = M;
    for(int i=0; i<m; i++){
        link[U[i]].push_back(V[i]);
        link[V[i]].push_back(U[i]);
    }

    for(int i=0; i<n; i++) par[i] = 1004;
    makeTree(0);

    for(int x=0; x<k; x++){
        bfs(x);
    }

    for(int i=1; i<n; i++){
        for(int j=0; j<10; j++) encode_bit(!!(par[i] & (1<<j)));
    }

    int kxx[]={1, 3, 9, 27, 81};
    for(int d=0; d<k; d++){
        for(int j=0; j<10; j++) encode_bit(!!(dist[d][0] & (1<<j)));
        for(int i=1; i<n; i+=5){
            int tmp = 0;
            for(int x=i; x<i+5 && x<n; x++){
                tmp += kxx[x-i] * (dist[d][x] - dist[d][par[x]] + 1);
            }
            for(int j=0; j<8; j++) encode_bit(!!(tmp & (1<<j)));
        }
    }
}
#include <bits/stdc++.h>
#include "grader.h"
#include "decoder.h"

using namespace std;

namespace{
    int n, k;
    int par[1002];
    vector<int> childs[1002];
    int weight[1002];
}

void dfs(int x, int sum = 0){
    weight[x] += sum;
    for(auto &y: childs[x]){
        dfs(y, weight[x]);
    }
}

void decode(int N, int K){
    n = N, k = K;
    for(int i=1; i<n; i++){
        int tmp = 0;
        for(int j=0; j<10; j++){
            tmp += (1<<j) * decode_bit();
        }
        par[i] = tmp;
        childs[tmp].push_back(i);
    }

    int kxx[]={1, 3, 9, 27, 81};
    for(int d=0; d<k; d++){
        int base = 0;
        for(int j=0; j<10; j++) base += (1<<j) * decode_bit();
        for(int i=1; i<n; i+=5){
            int tmp = 0;
            for(int j=0; j<8; j++) tmp += (1<<j) * decode_bit();

            for(int j=0; j<5; j++) weight[i+j] = (tmp/kxx[j])%3-1;
        }

        dfs(0);
        for(int i=0; i<n; i++){
            hops(d, i, base + weight[i]);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 275 ms 11776 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 3 ms 4736 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 5720 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 3 ms 4736 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 35 ms 6116 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 34 ms 5768 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 60 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 27 ms 5752 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 38 ms 5696 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 34 ms 5888 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 27 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 76 ms 6264 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 39 ms 5760 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 34 ms 5780 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 6320 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 66 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 73 ms 6396 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 41 ms 6060 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 73 ms 6812 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 82 ms 6960 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 6296 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 83 ms 7372 KB Output is correct - 67950 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 275 ms 11776 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 3 ms 4736 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 5720 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 3 ms 4736 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 35 ms 6116 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 34 ms 5768 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 60 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 27 ms 5752 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 38 ms 5696 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 34 ms 5888 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 27 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 76 ms 6264 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 39 ms 5760 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 34 ms 5780 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 6320 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 66 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 73 ms 6396 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 41 ms 6060 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 73 ms 6812 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 82 ms 6960 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 6296 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 83 ms 7372 KB Output is correct - 67950 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 275 ms 11776 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 3 ms 4736 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 5720 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 3 ms 4736 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 35 ms 6116 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 34 ms 5768 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 60 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 27 ms 5752 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 38 ms 5696 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 34 ms 5888 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 27 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 76 ms 6264 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 39 ms 5760 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 34 ms 5780 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 6320 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 66 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 73 ms 6396 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 41 ms 6060 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 73 ms 6812 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 82 ms 6960 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 6296 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 83 ms 7372 KB Output is correct - 67950 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 275 ms 11776 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 3 ms 4736 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 5720 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 3 ms 4736 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 35 ms 6116 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 34 ms 5768 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 60 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 27 ms 5752 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 38 ms 5696 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 34 ms 5888 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 27 ms 5632 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 76 ms 6264 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 39 ms 5760 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 34 ms 5780 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 6320 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 66 ms 6140 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 73 ms 6396 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 41 ms 6060 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 73 ms 6812 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 82 ms 6960 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 6296 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 83 ms 7372 KB Output is correct - 67950 call(s) of encode_bit()