답안 #395062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395062 2021-04-27T16:59:29 Z MarcoMeijer 저장 (Saveit) (IOI10_saveit) C++14
75 / 100
359 ms 10724 KB
#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second

void writeSmallInt(int x, int bits) {
    RE(i,bits) {
        bool b = false;
        if(x & (1<<i)) b = 1;
        encode_bit(b);
    }
}

void encode(int nv, int nh, int ne, int *v1, int *v2) {
    // create original graph
    vector<vi> adj; adj.resize(nv);
    RE(i,ne) {
        adj[v1[i]].pb(v2[i]);
        adj[v2[i]].pb(v1[i]);
    }

    // spanning tree
    vector<vi> chl; chl.resize(nv);
    vi parent; parent.assign(nv, -1);

    // fill dist
    vector<vi> dist; dist.resize(nh);
    RE(h,nh) {
        dist[h].assign(nv,-1);
        queue<int> q;
        q.push(h); dist[h][h] = 0;
        while(!q.empty()) {
            int u = q.front(); q.pop();
            FOR(v,adj[u]) {
                if(dist[h][v] != -1) continue;
                dist[h][v] = dist[h][u] + 1;
                q.push(v);
                if(h == 0) chl[u].pb(v), parent[v] = u; // create spanning tree
            }
        }
    }

    // write the spanning tree
    REP(u,1,nv) writeSmallInt(parent[u],10);
    RE(u,nv) sort(all(chl[u]));

    // writing the distances
    REP(h,1,nh) {
        function<void(int)> writeDist = [&](int u) {
            if(parent[u] != -1)
                writeSmallInt(dist[h][u] - dist[h][parent[u]] + 1, 2);
            FOR(v,chl[u]) writeDist(v);
        };
        writeDist(0);
    }
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second

int readSmallInt(int bits) {
    int res = 0;
    RE(i,bits) {
        bool b = decode_bit();
        if(b) res |= (1<<i);
    }
    return res;
}

void decode(int nv, int nh) {
    // spanning tree
    vector<vi> chl; chl.resize(nv);
    vi parent; parent.assign(nv, -1);
    
    // distance array
    vector<vi> dist; dist.assign(nh, vi(nv,0));

    // read the spanning tree
    REP(u,1,nv) {
        parent[u] = readSmallInt(10);
        chl[parent[u]].pb(u);
    }
    function<void(int)> dfsDist = [&](int u) {
        FOR(v,chl[u]) {
            dist[0][v] = dist[0][u] + 1;
            dfsDist(v);
        }
    };
    dfsDist(0);

    // reading the distances
    REP(h,1,nh) {
        function<void(int)> readDist = [&](int u) {
            if(parent[u] != -1) {
                int dif = readSmallInt(2) - 1;
                dist[h][u] = dist[h][parent[u]] + dif;
            }
            FOR(v,chl[u]) readDist(v);
        };
        readDist(0);
        int delta = -dist[h][h];
        RE(u,nv) dist[h][u] += delta;
    }

    // returning the answer
    RE(i,nh) RE(j,nv) hops(i,j,dist[i][j]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 10724 KB Output is partially correct - 79920 call(s) of encode_bit()
2 Correct 3 ms 4580 KB Output is correct - 56 call(s) of encode_bit()
3 Correct 28 ms 5592 KB Output is partially correct - 71920 call(s) of encode_bit()
4 Correct 3 ms 4576 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 33 ms 5796 KB Output is partially correct - 71920 call(s) of encode_bit()
6 Correct 35 ms 5780 KB Output is partially correct - 79920 call(s) of encode_bit()
7 Correct 52 ms 6236 KB Output is partially correct - 79920 call(s) of encode_bit()
8 Correct 28 ms 5716 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 31 ms 5624 KB Output is partially correct - 79920 call(s) of encode_bit()
10 Correct 32 ms 5716 KB Output is partially correct - 79920 call(s) of encode_bit()
11 Correct 35 ms 5924 KB Output is partially correct - 79920 call(s) of encode_bit()
12 Correct 34 ms 5732 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 63 ms 6284 KB Output is partially correct - 79920 call(s) of encode_bit()
14 Correct 32 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
15 Correct 33 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
16 Correct 60 ms 6292 KB Output is partially correct - 79920 call(s) of encode_bit()
17 Correct 51 ms 6160 KB Output is partially correct - 79920 call(s) of encode_bit()
18 Correct 63 ms 6468 KB Output is partially correct - 79920 call(s) of encode_bit()
19 Correct 49 ms 6100 KB Output is partially correct - 79920 call(s) of encode_bit()
20 Correct 76 ms 6740 KB Output is partially correct - 79920 call(s) of encode_bit()
21 Correct 84 ms 6792 KB Output is partially correct - 79920 call(s) of encode_bit()
22 Correct 70 ms 6340 KB Output is partially correct - 79920 call(s) of encode_bit()
23 Correct 100 ms 7036 KB Output is partially correct - 79920 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 10724 KB Output is partially correct - 79920 call(s) of encode_bit()
2 Correct 3 ms 4580 KB Output is correct - 56 call(s) of encode_bit()
3 Correct 28 ms 5592 KB Output is partially correct - 71920 call(s) of encode_bit()
4 Correct 3 ms 4576 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 33 ms 5796 KB Output is partially correct - 71920 call(s) of encode_bit()
6 Correct 35 ms 5780 KB Output is partially correct - 79920 call(s) of encode_bit()
7 Correct 52 ms 6236 KB Output is partially correct - 79920 call(s) of encode_bit()
8 Correct 28 ms 5716 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 31 ms 5624 KB Output is partially correct - 79920 call(s) of encode_bit()
10 Correct 32 ms 5716 KB Output is partially correct - 79920 call(s) of encode_bit()
11 Correct 35 ms 5924 KB Output is partially correct - 79920 call(s) of encode_bit()
12 Correct 34 ms 5732 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 63 ms 6284 KB Output is partially correct - 79920 call(s) of encode_bit()
14 Correct 32 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
15 Correct 33 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
16 Correct 60 ms 6292 KB Output is partially correct - 79920 call(s) of encode_bit()
17 Correct 51 ms 6160 KB Output is partially correct - 79920 call(s) of encode_bit()
18 Correct 63 ms 6468 KB Output is partially correct - 79920 call(s) of encode_bit()
19 Correct 49 ms 6100 KB Output is partially correct - 79920 call(s) of encode_bit()
20 Correct 76 ms 6740 KB Output is partially correct - 79920 call(s) of encode_bit()
21 Correct 84 ms 6792 KB Output is partially correct - 79920 call(s) of encode_bit()
22 Correct 70 ms 6340 KB Output is partially correct - 79920 call(s) of encode_bit()
23 Correct 100 ms 7036 KB Output is partially correct - 79920 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 10724 KB Output is partially correct - 79920 call(s) of encode_bit()
2 Correct 3 ms 4580 KB Output is correct - 56 call(s) of encode_bit()
3 Correct 28 ms 5592 KB Output is partially correct - 71920 call(s) of encode_bit()
4 Correct 3 ms 4576 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 33 ms 5796 KB Output is partially correct - 71920 call(s) of encode_bit()
6 Correct 35 ms 5780 KB Output is partially correct - 79920 call(s) of encode_bit()
7 Correct 52 ms 6236 KB Output is partially correct - 79920 call(s) of encode_bit()
8 Correct 28 ms 5716 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 31 ms 5624 KB Output is partially correct - 79920 call(s) of encode_bit()
10 Correct 32 ms 5716 KB Output is partially correct - 79920 call(s) of encode_bit()
11 Correct 35 ms 5924 KB Output is partially correct - 79920 call(s) of encode_bit()
12 Correct 34 ms 5732 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 63 ms 6284 KB Output is partially correct - 79920 call(s) of encode_bit()
14 Correct 32 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
15 Correct 33 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
16 Correct 60 ms 6292 KB Output is partially correct - 79920 call(s) of encode_bit()
17 Correct 51 ms 6160 KB Output is partially correct - 79920 call(s) of encode_bit()
18 Correct 63 ms 6468 KB Output is partially correct - 79920 call(s) of encode_bit()
19 Correct 49 ms 6100 KB Output is partially correct - 79920 call(s) of encode_bit()
20 Correct 76 ms 6740 KB Output is partially correct - 79920 call(s) of encode_bit()
21 Correct 84 ms 6792 KB Output is partially correct - 79920 call(s) of encode_bit()
22 Correct 70 ms 6340 KB Output is partially correct - 79920 call(s) of encode_bit()
23 Correct 100 ms 7036 KB Output is partially correct - 79920 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 10724 KB Output is partially correct - 79920 call(s) of encode_bit()
2 Correct 3 ms 4580 KB Output is correct - 56 call(s) of encode_bit()
3 Correct 28 ms 5592 KB Output is partially correct - 71920 call(s) of encode_bit()
4 Correct 3 ms 4576 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 33 ms 5796 KB Output is partially correct - 71920 call(s) of encode_bit()
6 Correct 35 ms 5780 KB Output is partially correct - 79920 call(s) of encode_bit()
7 Correct 52 ms 6236 KB Output is partially correct - 79920 call(s) of encode_bit()
8 Correct 28 ms 5716 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 31 ms 5624 KB Output is partially correct - 79920 call(s) of encode_bit()
10 Correct 32 ms 5716 KB Output is partially correct - 79920 call(s) of encode_bit()
11 Correct 35 ms 5924 KB Output is partially correct - 79920 call(s) of encode_bit()
12 Correct 34 ms 5732 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 63 ms 6284 KB Output is partially correct - 79920 call(s) of encode_bit()
14 Correct 32 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
15 Correct 33 ms 5868 KB Output is partially correct - 79920 call(s) of encode_bit()
16 Correct 60 ms 6292 KB Output is partially correct - 79920 call(s) of encode_bit()
17 Correct 51 ms 6160 KB Output is partially correct - 79920 call(s) of encode_bit()
18 Correct 63 ms 6468 KB Output is partially correct - 79920 call(s) of encode_bit()
19 Correct 49 ms 6100 KB Output is partially correct - 79920 call(s) of encode_bit()
20 Correct 76 ms 6740 KB Output is partially correct - 79920 call(s) of encode_bit()
21 Correct 84 ms 6792 KB Output is partially correct - 79920 call(s) of encode_bit()
22 Correct 70 ms 6340 KB Output is partially correct - 79920 call(s) of encode_bit()
23 Correct 100 ms 7036 KB Output is partially correct - 79920 call(s) of encode_bit()