답안 #512474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
512474 2022-01-16T11:37:10 Z alextodoran 저장 (Saveit) (IOI10_saveit) C++17
0 / 100
255 ms 10588 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);
        int x = 0, p = 1;
        for (int i = 1; i < N; i++) {
            int u = order[i];
            int d = 1 + (dist[h][u] - dist[h][parent[u]]);
            x += p * d; p *= 3;
            if (i % 3 == 0 || i == N - 1) {
                encode_int(x, 5);
                x = 0; p = 1;
            }
        }
        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;
        int x = decode_int(5);
        for (int i = 1; i < N; i++) {
            int u = order[i];
            int d = x % 3 - 1; x /= 3;
            dist[h][u] = dist[h][parent[u]] + d;
            if (i % 3 == 0) {
                x = decode_int(5);
            }
        }
        order.clear();
    }
    for (int h = 0; h < H; h++) {
        for (int u = 0; u < N; u++) {
            hops(h, u, dist[h][u]);
        }
    }

    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 Incorrect 255 ms 10588 KB too many decode_bit() calls
2 Correct 2 ms 4580 KB Output is correct - 70 call(s) of encode_bit()
3 Correct 23 ms 5712 KB Output is correct - 62990 call(s) of encode_bit()
4 Correct 2 ms 4588 KB Output is correct - 90 call(s) of encode_bit()
5 Correct 24 ms 5852 KB Output is correct - 62990 call(s) of encode_bit()
6 Incorrect 20 ms 5976 KB too many decode_bit() calls
7 Incorrect 36 ms 6256 KB too many decode_bit() calls
8 Incorrect 18 ms 5732 KB too many decode_bit() calls
9 Incorrect 20 ms 5740 KB too many decode_bit() calls
10 Incorrect 22 ms 5732 KB too many decode_bit() calls
11 Incorrect 28 ms 5836 KB too many decode_bit() calls
12 Incorrect 18 ms 5704 KB too many decode_bit() calls
13 Incorrect 60 ms 6232 KB too many decode_bit() calls
14 Incorrect 20 ms 5708 KB too many decode_bit() calls
15 Incorrect 24 ms 5668 KB too many decode_bit() calls
16 Incorrect 43 ms 6344 KB too many decode_bit() calls
17 Incorrect 41 ms 6284 KB too many decode_bit() calls
18 Incorrect 58 ms 6384 KB too many decode_bit() calls
19 Incorrect 35 ms 6032 KB too many decode_bit() calls
20 Incorrect 57 ms 6688 KB too many decode_bit() calls
21 Incorrect 71 ms 6904 KB too many decode_bit() calls
22 Incorrect 40 ms 6348 KB too many decode_bit() calls
23 Incorrect 96 ms 7124 KB too many decode_bit() calls
# 결과 실행 시간 메모리 Grader output
1 Incorrect 255 ms 10588 KB too many decode_bit() calls
2 Correct 2 ms 4580 KB Output is correct - 70 call(s) of encode_bit()
3 Correct 23 ms 5712 KB Output is correct - 62990 call(s) of encode_bit()
4 Correct 2 ms 4588 KB Output is correct - 90 call(s) of encode_bit()
5 Correct 24 ms 5852 KB Output is correct - 62990 call(s) of encode_bit()
6 Incorrect 20 ms 5976 KB too many decode_bit() calls
7 Incorrect 36 ms 6256 KB too many decode_bit() calls
8 Incorrect 18 ms 5732 KB too many decode_bit() calls
9 Incorrect 20 ms 5740 KB too many decode_bit() calls
10 Incorrect 22 ms 5732 KB too many decode_bit() calls
11 Incorrect 28 ms 5836 KB too many decode_bit() calls
12 Incorrect 18 ms 5704 KB too many decode_bit() calls
13 Incorrect 60 ms 6232 KB too many decode_bit() calls
14 Incorrect 20 ms 5708 KB too many decode_bit() calls
15 Incorrect 24 ms 5668 KB too many decode_bit() calls
16 Incorrect 43 ms 6344 KB too many decode_bit() calls
17 Incorrect 41 ms 6284 KB too many decode_bit() calls
18 Incorrect 58 ms 6384 KB too many decode_bit() calls
19 Incorrect 35 ms 6032 KB too many decode_bit() calls
20 Incorrect 57 ms 6688 KB too many decode_bit() calls
21 Incorrect 71 ms 6904 KB too many decode_bit() calls
22 Incorrect 40 ms 6348 KB too many decode_bit() calls
23 Incorrect 96 ms 7124 KB too many decode_bit() calls
# 결과 실행 시간 메모리 Grader output
1 Incorrect 255 ms 10588 KB too many decode_bit() calls
2 Correct 2 ms 4580 KB Output is correct - 70 call(s) of encode_bit()
3 Correct 23 ms 5712 KB Output is correct - 62990 call(s) of encode_bit()
4 Correct 2 ms 4588 KB Output is correct - 90 call(s) of encode_bit()
5 Correct 24 ms 5852 KB Output is correct - 62990 call(s) of encode_bit()
6 Incorrect 20 ms 5976 KB too many decode_bit() calls
7 Incorrect 36 ms 6256 KB too many decode_bit() calls
8 Incorrect 18 ms 5732 KB too many decode_bit() calls
9 Incorrect 20 ms 5740 KB too many decode_bit() calls
10 Incorrect 22 ms 5732 KB too many decode_bit() calls
11 Incorrect 28 ms 5836 KB too many decode_bit() calls
12 Incorrect 18 ms 5704 KB too many decode_bit() calls
13 Incorrect 60 ms 6232 KB too many decode_bit() calls
14 Incorrect 20 ms 5708 KB too many decode_bit() calls
15 Incorrect 24 ms 5668 KB too many decode_bit() calls
16 Incorrect 43 ms 6344 KB too many decode_bit() calls
17 Incorrect 41 ms 6284 KB too many decode_bit() calls
18 Incorrect 58 ms 6384 KB too many decode_bit() calls
19 Incorrect 35 ms 6032 KB too many decode_bit() calls
20 Incorrect 57 ms 6688 KB too many decode_bit() calls
21 Incorrect 71 ms 6904 KB too many decode_bit() calls
22 Incorrect 40 ms 6348 KB too many decode_bit() calls
23 Incorrect 96 ms 7124 KB too many decode_bit() calls
# 결과 실행 시간 메모리 Grader output
1 Incorrect 255 ms 10588 KB too many decode_bit() calls
2 Correct 2 ms 4580 KB Output is correct - 70 call(s) of encode_bit()
3 Correct 23 ms 5712 KB Output is correct - 62990 call(s) of encode_bit()
4 Correct 2 ms 4588 KB Output is correct - 90 call(s) of encode_bit()
5 Correct 24 ms 5852 KB Output is correct - 62990 call(s) of encode_bit()
6 Incorrect 20 ms 5976 KB too many decode_bit() calls
7 Incorrect 36 ms 6256 KB too many decode_bit() calls
8 Incorrect 18 ms 5732 KB too many decode_bit() calls
9 Incorrect 20 ms 5740 KB too many decode_bit() calls
10 Incorrect 22 ms 5732 KB too many decode_bit() calls
11 Incorrect 28 ms 5836 KB too many decode_bit() calls
12 Incorrect 18 ms 5704 KB too many decode_bit() calls
13 Incorrect 60 ms 6232 KB too many decode_bit() calls
14 Incorrect 20 ms 5708 KB too many decode_bit() calls
15 Incorrect 24 ms 5668 KB too many decode_bit() calls
16 Incorrect 43 ms 6344 KB too many decode_bit() calls
17 Incorrect 41 ms 6284 KB too many decode_bit() calls
18 Incorrect 58 ms 6384 KB too many decode_bit() calls
19 Incorrect 35 ms 6032 KB too many decode_bit() calls
20 Incorrect 57 ms 6688 KB too many decode_bit() calls
21 Incorrect 71 ms 6904 KB too many decode_bit() calls
22 Incorrect 40 ms 6348 KB too many decode_bit() calls
23 Incorrect 96 ms 7124 KB too many decode_bit() calls