답안 #747205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747205 2023-05-23T22:58:44 Z finn__ 저장 (Saveit) (IOI10_saveit) C++17
100 / 100
186 ms 10444 KB
#include "grader.h"
#include "encoder.h"

#include <bits/stdc++.h>
using namespace std;

void encode_package(int p[3])
{
    int z = 0;
    for (size_t i = 0; i < 3; ++i)
        z = z * 3 + p[i] + 1;
    for (size_t i = 4; i < 5; --i)
        encode_bit((z >> i) & 1);
}

void encode(int n, int h, int m, int *a, int *b)
{
    if (!h)
        return;
    vector<vector<int>> g(n), d(h, vector<int>(n, -1));
    vector<int> p(n), bfs_order;
    for (size_t i = 0; i < m; ++i)
        g[a[i]].push_back(b[i]), g[b[i]].push_back(a[i]);
    for (size_t i = 0; i < n; ++i)
        sort(g[i].begin(), g[i].end());

    for (size_t i = 0; i < h; ++i)
    {
        queue<int> q;
        q.push(i);
        d[i][i] = 0;
        while (!q.empty())
        {
            int u = q.front();
            q.pop();
            for (int const &v : g[u])
                if (d[i][v] == -1)
                {
                    d[i][v] = d[i][u] + 1;
                    q.push(v);
                    if (!i)
                        p[v] = u, bfs_order.push_back(v);
                }
        }
    }

    assert(bfs_order.size() == n - 1);
    for (size_t i = 1; i < n; ++i) /* encode bfs tree from 0 */
        for (size_t j = 9; j < 10; --j)
            encode_bit((p[i] >> j) & 1);

    int c[3];
    size_t l = 0;
    for (int const &i : bfs_order) /* encode distance changes */
    {
        for (size_t k = 1; k < h; ++k)
        {
            c[l++] = d[k][i] - d[k][p[i]];
            if (l == 3)
                encode_package(c), l = 0;
        }
    }
    if (l)
        encode_package(c);
}
#include "grader.h"
#include "decoder.h"

#include <bits/stdc++.h>
using namespace std;

void decode_package(int p[3])
{
    int z = 0;
    for (size_t i = 0; i < 5; ++i)
        z = (z << 1) | decode_bit();
    for (size_t i = 2; i < 3; --i)
        p[i] = (z % 3) - 1, z /= 3;
}

void decode(int n, int h)
{
    if (!h)
        return;
    vector<vector<int>> t(n), d(h, vector<int>(n));
    vector<int> p(n), bfs_order;
    hops(0, 0, 0);
    for (size_t i = 1; i < n; ++i)
    {
        for (size_t j = 0; j < 10; ++j)
            p[i] = (p[i] << 1) | decode_bit();
        t[p[i]].push_back(i);
    }

    queue<int> q;
    q.push(0);
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int const &v : t[u])
            bfs_order.push_back(v), q.push(v);
    }
    assert(bfs_order.size() == n - 1);
    for (int const &i : bfs_order)
        d[0][i] = d[0][p[i]] + 1, hops(0, i, d[0][i]);
    for (size_t i = 1; i < h; ++i)
        d[i][0] = d[0][i], hops(i, 0, d[0][i]);

    size_t l = 3;
    int c[3];
    for (int const &i : bfs_order)
    {
        for (size_t k = 1; k < h; ++k)
        {
            if (l == 3)
                decode_package(c), l = 0;
            d[k][i] = d[k][p[i]] + c[l++];
            hops(k, i, d[k][i]);
        }
    }
}

Compilation message

encoder.cpp: In function 'void encode(int, int, int, int*, int*)':
encoder.cpp:22:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     for (size_t i = 0; i < m; ++i)
      |                        ~~^~~
encoder.cpp:24:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |     for (size_t i = 0; i < n; ++i)
      |                        ~~^~~
encoder.cpp:27:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     for (size_t i = 0; i < h; ++i)
      |                        ~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from encoder.cpp:4:
encoder.cpp:47:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |     assert(bfs_order.size() == n - 1);
      |            ~~~~~~~~~~~~~~~~~^~~~~~~~
encoder.cpp:48:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |     for (size_t i = 1; i < n; ++i) /* encode bfs tree from 0 */
      |                        ~~^~~
encoder.cpp:56:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |         for (size_t k = 1; k < h; ++k)
      |                            ~~^~~

decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:23:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |     for (size_t i = 1; i < n; ++i)
      |                        ~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from decoder.cpp:4:
decoder.cpp:39:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |     assert(bfs_order.size() == n - 1);
      |            ~~~~~~~~~~~~~~~~~^~~~~~~~
decoder.cpp:42:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |     for (size_t i = 1; i < h; ++i)
      |                        ~~^~~
decoder.cpp:49:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         for (size_t k = 1; k < h; ++k)
      |                            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 10444 KB Output is correct - 68265 call(s) of encode_bit()
2 Correct 2 ms 4604 KB Output is correct - 55 call(s) of encode_bit()
3 Correct 18 ms 5496 KB Output is correct - 61435 call(s) of encode_bit()
4 Correct 3 ms 4616 KB Output is correct - 70 call(s) of encode_bit()
5 Correct 27 ms 5740 KB Output is correct - 61435 call(s) of encode_bit()
6 Correct 27 ms 5764 KB Output is correct - 68265 call(s) of encode_bit()
7 Correct 36 ms 6088 KB Output is correct - 68265 call(s) of encode_bit()
8 Correct 20 ms 5620 KB Output is correct - 65600 call(s) of encode_bit()
9 Correct 26 ms 5776 KB Output is correct - 68265 call(s) of encode_bit()
10 Correct 23 ms 5932 KB Output is correct - 68265 call(s) of encode_bit()
11 Correct 24 ms 5908 KB Output is correct - 68265 call(s) of encode_bit()
12 Correct 20 ms 5660 KB Output is correct - 68265 call(s) of encode_bit()
13 Correct 54 ms 6344 KB Output is correct - 68265 call(s) of encode_bit()
14 Correct 20 ms 5668 KB Output is correct - 68265 call(s) of encode_bit()
15 Correct 20 ms 5804 KB Output is correct - 68265 call(s) of encode_bit()
16 Correct 43 ms 6252 KB Output is correct - 68265 call(s) of encode_bit()
17 Correct 48 ms 6164 KB Output is correct - 68265 call(s) of encode_bit()
18 Correct 46 ms 6280 KB Output is correct - 68265 call(s) of encode_bit()
19 Correct 34 ms 5992 KB Output is correct - 68265 call(s) of encode_bit()
20 Correct 63 ms 6856 KB Output is correct - 68265 call(s) of encode_bit()
21 Correct 63 ms 6824 KB Output is correct - 68265 call(s) of encode_bit()
22 Correct 47 ms 6216 KB Output is correct - 68265 call(s) of encode_bit()
23 Correct 63 ms 6932 KB Output is correct - 68265 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 10444 KB Output is correct - 68265 call(s) of encode_bit()
2 Correct 2 ms 4604 KB Output is correct - 55 call(s) of encode_bit()
3 Correct 18 ms 5496 KB Output is correct - 61435 call(s) of encode_bit()
4 Correct 3 ms 4616 KB Output is correct - 70 call(s) of encode_bit()
5 Correct 27 ms 5740 KB Output is correct - 61435 call(s) of encode_bit()
6 Correct 27 ms 5764 KB Output is correct - 68265 call(s) of encode_bit()
7 Correct 36 ms 6088 KB Output is correct - 68265 call(s) of encode_bit()
8 Correct 20 ms 5620 KB Output is correct - 65600 call(s) of encode_bit()
9 Correct 26 ms 5776 KB Output is correct - 68265 call(s) of encode_bit()
10 Correct 23 ms 5932 KB Output is correct - 68265 call(s) of encode_bit()
11 Correct 24 ms 5908 KB Output is correct - 68265 call(s) of encode_bit()
12 Correct 20 ms 5660 KB Output is correct - 68265 call(s) of encode_bit()
13 Correct 54 ms 6344 KB Output is correct - 68265 call(s) of encode_bit()
14 Correct 20 ms 5668 KB Output is correct - 68265 call(s) of encode_bit()
15 Correct 20 ms 5804 KB Output is correct - 68265 call(s) of encode_bit()
16 Correct 43 ms 6252 KB Output is correct - 68265 call(s) of encode_bit()
17 Correct 48 ms 6164 KB Output is correct - 68265 call(s) of encode_bit()
18 Correct 46 ms 6280 KB Output is correct - 68265 call(s) of encode_bit()
19 Correct 34 ms 5992 KB Output is correct - 68265 call(s) of encode_bit()
20 Correct 63 ms 6856 KB Output is correct - 68265 call(s) of encode_bit()
21 Correct 63 ms 6824 KB Output is correct - 68265 call(s) of encode_bit()
22 Correct 47 ms 6216 KB Output is correct - 68265 call(s) of encode_bit()
23 Correct 63 ms 6932 KB Output is correct - 68265 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 10444 KB Output is correct - 68265 call(s) of encode_bit()
2 Correct 2 ms 4604 KB Output is correct - 55 call(s) of encode_bit()
3 Correct 18 ms 5496 KB Output is correct - 61435 call(s) of encode_bit()
4 Correct 3 ms 4616 KB Output is correct - 70 call(s) of encode_bit()
5 Correct 27 ms 5740 KB Output is correct - 61435 call(s) of encode_bit()
6 Correct 27 ms 5764 KB Output is correct - 68265 call(s) of encode_bit()
7 Correct 36 ms 6088 KB Output is correct - 68265 call(s) of encode_bit()
8 Correct 20 ms 5620 KB Output is correct - 65600 call(s) of encode_bit()
9 Correct 26 ms 5776 KB Output is correct - 68265 call(s) of encode_bit()
10 Correct 23 ms 5932 KB Output is correct - 68265 call(s) of encode_bit()
11 Correct 24 ms 5908 KB Output is correct - 68265 call(s) of encode_bit()
12 Correct 20 ms 5660 KB Output is correct - 68265 call(s) of encode_bit()
13 Correct 54 ms 6344 KB Output is correct - 68265 call(s) of encode_bit()
14 Correct 20 ms 5668 KB Output is correct - 68265 call(s) of encode_bit()
15 Correct 20 ms 5804 KB Output is correct - 68265 call(s) of encode_bit()
16 Correct 43 ms 6252 KB Output is correct - 68265 call(s) of encode_bit()
17 Correct 48 ms 6164 KB Output is correct - 68265 call(s) of encode_bit()
18 Correct 46 ms 6280 KB Output is correct - 68265 call(s) of encode_bit()
19 Correct 34 ms 5992 KB Output is correct - 68265 call(s) of encode_bit()
20 Correct 63 ms 6856 KB Output is correct - 68265 call(s) of encode_bit()
21 Correct 63 ms 6824 KB Output is correct - 68265 call(s) of encode_bit()
22 Correct 47 ms 6216 KB Output is correct - 68265 call(s) of encode_bit()
23 Correct 63 ms 6932 KB Output is correct - 68265 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 10444 KB Output is correct - 68265 call(s) of encode_bit()
2 Correct 2 ms 4604 KB Output is correct - 55 call(s) of encode_bit()
3 Correct 18 ms 5496 KB Output is correct - 61435 call(s) of encode_bit()
4 Correct 3 ms 4616 KB Output is correct - 70 call(s) of encode_bit()
5 Correct 27 ms 5740 KB Output is correct - 61435 call(s) of encode_bit()
6 Correct 27 ms 5764 KB Output is correct - 68265 call(s) of encode_bit()
7 Correct 36 ms 6088 KB Output is correct - 68265 call(s) of encode_bit()
8 Correct 20 ms 5620 KB Output is correct - 65600 call(s) of encode_bit()
9 Correct 26 ms 5776 KB Output is correct - 68265 call(s) of encode_bit()
10 Correct 23 ms 5932 KB Output is correct - 68265 call(s) of encode_bit()
11 Correct 24 ms 5908 KB Output is correct - 68265 call(s) of encode_bit()
12 Correct 20 ms 5660 KB Output is correct - 68265 call(s) of encode_bit()
13 Correct 54 ms 6344 KB Output is correct - 68265 call(s) of encode_bit()
14 Correct 20 ms 5668 KB Output is correct - 68265 call(s) of encode_bit()
15 Correct 20 ms 5804 KB Output is correct - 68265 call(s) of encode_bit()
16 Correct 43 ms 6252 KB Output is correct - 68265 call(s) of encode_bit()
17 Correct 48 ms 6164 KB Output is correct - 68265 call(s) of encode_bit()
18 Correct 46 ms 6280 KB Output is correct - 68265 call(s) of encode_bit()
19 Correct 34 ms 5992 KB Output is correct - 68265 call(s) of encode_bit()
20 Correct 63 ms 6856 KB Output is correct - 68265 call(s) of encode_bit()
21 Correct 63 ms 6824 KB Output is correct - 68265 call(s) of encode_bit()
22 Correct 47 ms 6216 KB Output is correct - 68265 call(s) of encode_bit()
23 Correct 63 ms 6932 KB Output is correct - 68265 call(s) of encode_bit()