답안 #512469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
512469 2022-01-16T11:28:59 Z alextodoran 저장 (Saveit) (IOI10_saveit) C++17
50 / 100
300 ms 10572 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

static const int N_MAX = 1000;
static const int H_MAX = 36;

static int N, H, E;

static int dist[H_MAX][N_MAX];

static int parent[N_MAX];

static vector <int> adj[N_MAX];

static vector <int> order;

void dfsRec (int u) {
    order.push_back(u);
    for (int v : adj[u]) {
        if (parent[v] == -1) {
            parent[v] = u;
            dfsRec(v);
        }
    }
}
void dfs (int h) {
    for (int u = 0; u < N; u++) {
        parent[u] = -1;
    }
    parent[h] = h;
    dfsRec(h);
}

#include "grader.h"
#include "encoder.h"

void encode_bit (int bit);

void encode_int (int val, int len) {
    for (int bit = len - 1; bit >= 0; bit--) {
        encode_bit((val >> bit) & 1);
    }
}

void bfs (int h, int dist[]) {
    for (int u = 0; u < N; u++) {
        dist[u] = -1;
    }
    queue <int> q;
    dist[h] = 0;
    q.push(h);
    while (q.empty() == false) {
        int u = q.front();
        q.pop();
        for (int v : adj[u]) {
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
}

void encode (int nv, int nh, int ne, int *v1, int *v2) {
    N = nv; H = nh; E = ne;
    for (int i = 0; i < E; i++) {
        adj[v1[i]].push_back(v2[i]);
        adj[v2[i]].push_back(v1[i]);
    }
    for (int u = 0; u < N; u++) {
        sort(adj[u].begin(), adj[u].end());
    }

    for (int h = 0; h < H; h++) {
        bfs(h, dist[h]);
    }

    dfs(0);
    for (int u = 0; u < N; u++) {
        adj[u].clear();
    }
    order.clear();
    for (int u = 1; u < N; u++) {
        encode_int(parent[u], 10);
        adj[u].push_back(parent[u]);
        adj[parent[u]].push_back(u);
    }
    for (int u = 0; u < N; u++) {
        sort(adj[u].begin(), adj[u].end());
    }

    for (int h = 0; h < H; h++) {
        dfs(h);
        for (int i = 1; i < N; i++) {
            int u = order[i];
            encode_int(1 + (dist[h][u] - dist[h][parent[u]]), 2);
        }
        order.clear();
    }

    for (int u = 0; u < N; u++) {
        adj[u].clear();
    }
}
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

static const int N_MAX = 1000;
static const int H_MAX = 36;

static int N, H, E;

static int dist[H_MAX][N_MAX];

static int parent[N_MAX];

static vector <int> adj[N_MAX];

static vector <int> order;

void dfsRec (int u) {
    order.push_back(u);
    for (int v : adj[u]) {
        if (parent[v] == -1) {
            parent[v] = u;
            dfsRec(v);
        }
    }
}
void dfs (int h) {
    for (int u = 0; u < N; u++) {
        parent[u] = -1;
    }
    parent[h] = h;
    dfsRec(h);
}

#include "grader.h"
#include "decoder.h"

int decode_bit ();

void hops (int a, int b, int d);

int decode_int (int len) {
    int val = 0;
    for (int bit = len - 1; bit >= 0; bit--) {
        val |= (decode_bit() << bit);
    }
    return val;
}

void decode (int nv, int nh) {
    N = nv; H = nh;
    for (int u = 1; u < N; u++) {
        parent[u] = decode_int(10);
        adj[u].push_back(parent[u]);
        adj[parent[u]].push_back(u);
    }
    for (int u = 0; u < N; u++) {
        sort(adj[u].begin(), adj[u].end());
    }

    for (int h = 0; h < H; h++) {
        dfs(h);
        dist[h][h] = 0;
        hops(h, h, dist[h][h]);
        for (int i = 1; i < N; i++) {
            int u = order[i];
            dist[h][u] = dist[h][parent[u]] + (decode_int(2) - 1);
            hops(h, u, dist[h][u]);
        }
        order.clear();
    }

    for (int u = 0; u < N; u++) {
        adj[u].clear();
    }
}

Compilation message

decoder.cpp:18:18: warning: 'E' defined but not used [-Wunused-variable]
   18 | static int N, H, E;
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 10572 KB Output is partially correct - 81918 call(s) of encode_bit()
2 Correct 2 ms 4580 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 22 ms 5724 KB Output is partially correct - 73718 call(s) of encode_bit()
4 Correct 1 ms 4588 KB Output is correct - 80 call(s) of encode_bit()
5 Correct 31 ms 5972 KB Output is partially correct - 73718 call(s) of encode_bit()
6 Correct 28 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
7 Correct 50 ms 6304 KB Output is partially correct - 81918 call(s) of encode_bit()
8 Correct 23 ms 5672 KB Output is partially correct - 78720 call(s) of encode_bit()
9 Correct 24 ms 5836 KB Output is partially correct - 81918 call(s) of encode_bit()
10 Correct 25 ms 5732 KB Output is partially correct - 81918 call(s) of encode_bit()
11 Correct 27 ms 5968 KB Output is partially correct - 81918 call(s) of encode_bit()
12 Correct 29 ms 5868 KB Output is partially correct - 81918 call(s) of encode_bit()
13 Correct 51 ms 6440 KB Output is partially correct - 81918 call(s) of encode_bit()
14 Correct 23 ms 5824 KB Output is partially correct - 81918 call(s) of encode_bit()
15 Correct 24 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
16 Correct 60 ms 6368 KB Output is partially correct - 81918 call(s) of encode_bit()
17 Correct 57 ms 6336 KB Output is partially correct - 81918 call(s) of encode_bit()
18 Correct 66 ms 6436 KB Output is partially correct - 81918 call(s) of encode_bit()
19 Correct 36 ms 6048 KB Output is partially correct - 81918 call(s) of encode_bit()
20 Correct 80 ms 6688 KB Output is partially correct - 81918 call(s) of encode_bit()
21 Correct 77 ms 6848 KB Output is partially correct - 81918 call(s) of encode_bit()
22 Correct 67 ms 6488 KB Output is partially correct - 81918 call(s) of encode_bit()
23 Correct 73 ms 7216 KB Output is partially correct - 81918 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 10572 KB Output is partially correct - 81918 call(s) of encode_bit()
2 Correct 2 ms 4580 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 22 ms 5724 KB Output is partially correct - 73718 call(s) of encode_bit()
4 Correct 1 ms 4588 KB Output is correct - 80 call(s) of encode_bit()
5 Correct 31 ms 5972 KB Output is partially correct - 73718 call(s) of encode_bit()
6 Correct 28 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
7 Correct 50 ms 6304 KB Output is partially correct - 81918 call(s) of encode_bit()
8 Correct 23 ms 5672 KB Output is partially correct - 78720 call(s) of encode_bit()
9 Correct 24 ms 5836 KB Output is partially correct - 81918 call(s) of encode_bit()
10 Correct 25 ms 5732 KB Output is partially correct - 81918 call(s) of encode_bit()
11 Correct 27 ms 5968 KB Output is partially correct - 81918 call(s) of encode_bit()
12 Correct 29 ms 5868 KB Output is partially correct - 81918 call(s) of encode_bit()
13 Correct 51 ms 6440 KB Output is partially correct - 81918 call(s) of encode_bit()
14 Correct 23 ms 5824 KB Output is partially correct - 81918 call(s) of encode_bit()
15 Correct 24 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
16 Correct 60 ms 6368 KB Output is partially correct - 81918 call(s) of encode_bit()
17 Correct 57 ms 6336 KB Output is partially correct - 81918 call(s) of encode_bit()
18 Correct 66 ms 6436 KB Output is partially correct - 81918 call(s) of encode_bit()
19 Correct 36 ms 6048 KB Output is partially correct - 81918 call(s) of encode_bit()
20 Correct 80 ms 6688 KB Output is partially correct - 81918 call(s) of encode_bit()
21 Correct 77 ms 6848 KB Output is partially correct - 81918 call(s) of encode_bit()
22 Correct 67 ms 6488 KB Output is partially correct - 81918 call(s) of encode_bit()
23 Correct 73 ms 7216 KB Output is partially correct - 81918 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 10572 KB Output is partially correct - 81918 call(s) of encode_bit()
2 Correct 2 ms 4580 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 22 ms 5724 KB Output is partially correct - 73718 call(s) of encode_bit()
4 Correct 1 ms 4588 KB Output is correct - 80 call(s) of encode_bit()
5 Correct 31 ms 5972 KB Output is partially correct - 73718 call(s) of encode_bit()
6 Correct 28 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
7 Correct 50 ms 6304 KB Output is partially correct - 81918 call(s) of encode_bit()
8 Correct 23 ms 5672 KB Output is partially correct - 78720 call(s) of encode_bit()
9 Correct 24 ms 5836 KB Output is partially correct - 81918 call(s) of encode_bit()
10 Correct 25 ms 5732 KB Output is partially correct - 81918 call(s) of encode_bit()
11 Correct 27 ms 5968 KB Output is partially correct - 81918 call(s) of encode_bit()
12 Correct 29 ms 5868 KB Output is partially correct - 81918 call(s) of encode_bit()
13 Correct 51 ms 6440 KB Output is partially correct - 81918 call(s) of encode_bit()
14 Correct 23 ms 5824 KB Output is partially correct - 81918 call(s) of encode_bit()
15 Correct 24 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
16 Correct 60 ms 6368 KB Output is partially correct - 81918 call(s) of encode_bit()
17 Correct 57 ms 6336 KB Output is partially correct - 81918 call(s) of encode_bit()
18 Correct 66 ms 6436 KB Output is partially correct - 81918 call(s) of encode_bit()
19 Correct 36 ms 6048 KB Output is partially correct - 81918 call(s) of encode_bit()
20 Correct 80 ms 6688 KB Output is partially correct - 81918 call(s) of encode_bit()
21 Correct 77 ms 6848 KB Output is partially correct - 81918 call(s) of encode_bit()
22 Correct 67 ms 6488 KB Output is partially correct - 81918 call(s) of encode_bit()
23 Correct 73 ms 7216 KB Output is partially correct - 81918 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 10572 KB Output is partially correct - 81918 call(s) of encode_bit()
2 Correct 2 ms 4580 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 22 ms 5724 KB Output is partially correct - 73718 call(s) of encode_bit()
4 Correct 1 ms 4588 KB Output is correct - 80 call(s) of encode_bit()
5 Correct 31 ms 5972 KB Output is partially correct - 73718 call(s) of encode_bit()
6 Correct 28 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
7 Correct 50 ms 6304 KB Output is partially correct - 81918 call(s) of encode_bit()
8 Correct 23 ms 5672 KB Output is partially correct - 78720 call(s) of encode_bit()
9 Correct 24 ms 5836 KB Output is partially correct - 81918 call(s) of encode_bit()
10 Correct 25 ms 5732 KB Output is partially correct - 81918 call(s) of encode_bit()
11 Correct 27 ms 5968 KB Output is partially correct - 81918 call(s) of encode_bit()
12 Correct 29 ms 5868 KB Output is partially correct - 81918 call(s) of encode_bit()
13 Correct 51 ms 6440 KB Output is partially correct - 81918 call(s) of encode_bit()
14 Correct 23 ms 5824 KB Output is partially correct - 81918 call(s) of encode_bit()
15 Correct 24 ms 5988 KB Output is partially correct - 81918 call(s) of encode_bit()
16 Correct 60 ms 6368 KB Output is partially correct - 81918 call(s) of encode_bit()
17 Correct 57 ms 6336 KB Output is partially correct - 81918 call(s) of encode_bit()
18 Correct 66 ms 6436 KB Output is partially correct - 81918 call(s) of encode_bit()
19 Correct 36 ms 6048 KB Output is partially correct - 81918 call(s) of encode_bit()
20 Correct 80 ms 6688 KB Output is partially correct - 81918 call(s) of encode_bit()
21 Correct 77 ms 6848 KB Output is partially correct - 81918 call(s) of encode_bit()
22 Correct 67 ms 6488 KB Output is partially correct - 81918 call(s) of encode_bit()
23 Correct 73 ms 7216 KB Output is partially correct - 81918 call(s) of encode_bit()