답안 #395053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395053 2021-04-27T16:49:56 Z MarcoMeijer 저장 (Saveit) (IOI10_saveit) C++14
50 / 100
245 ms 10496 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
            }
        }
    }

    // functions
    int curH = 0;
    function<void(int)> writeSpan = [&](int u) {
        FOR(v,chl[u]) {
            encode_bit(1);
            writeSmallInt(v,10);
            writeSpan(v);
        }
        encode_bit(0);
    };
    function<void(int)> writeDist = [&](int u) {
        if(parent[u] != -1)
            writeSmallInt(dist[curH][u] - dist[curH][parent[u]] + 1, 2);
        FOR(v,chl[u]) writeDist(v);
    };

    // calling the above functions
    writeSpan(0);
    REP(h,1,nh) {
        curH = h;
        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));

    // functions
    int curH = 0;
    function<void(int)> readSpan = [&](int u) {
        if(parent[u] != -1) {
            dist[0][u] = dist[0][parent[u]] + 1;
        }
        while(true) {
            bool b = decode_bit();
            if(!b) return;
            int v = readSmallInt(10);
            chl[u].pb(v);
            parent[v] = u;
            readSpan(v);
        }
    };
    function<void(int)> readDist = [&](int u) {
        if(parent[u] != -1) {
            int dif = readSmallInt(2) - 1;
            dist[curH][u] = dist[curH][parent[u]] + dif;
        }
        FOR(v,chl[u]) readDist(v);
    };

    // calling the above functions
    readSpan(0);
    REP(h,1,nh) {
        curH = h;
        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 245 ms 10496 KB Output is partially correct - 81919 call(s) of encode_bit()
2 Correct 3 ms 4592 KB Output is correct - 65 call(s) of encode_bit()
3 Correct 33 ms 5596 KB Output is partially correct - 73719 call(s) of encode_bit()
4 Correct 3 ms 4580 KB Output is correct - 81 call(s) of encode_bit()
5 Correct 32 ms 5748 KB Output is partially correct - 73719 call(s) of encode_bit()
6 Correct 33 ms 5856 KB Output is partially correct - 81919 call(s) of encode_bit()
7 Correct 60 ms 6172 KB Output is partially correct - 81919 call(s) of encode_bit()
8 Correct 30 ms 5820 KB Output is partially correct - 78721 call(s) of encode_bit()
9 Correct 33 ms 5780 KB Output is partially correct - 81919 call(s) of encode_bit()
10 Correct 33 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
11 Correct 39 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
12 Correct 32 ms 5864 KB Output is partially correct - 81919 call(s) of encode_bit()
13 Correct 57 ms 6348 KB Output is partially correct - 81919 call(s) of encode_bit()
14 Correct 36 ms 5892 KB Output is partially correct - 81919 call(s) of encode_bit()
15 Correct 34 ms 5932 KB Output is partially correct - 81919 call(s) of encode_bit()
16 Correct 65 ms 6248 KB Output is partially correct - 81919 call(s) of encode_bit()
17 Correct 66 ms 6372 KB Output is partially correct - 81919 call(s) of encode_bit()
18 Correct 63 ms 6428 KB Output is partially correct - 81919 call(s) of encode_bit()
19 Correct 48 ms 6000 KB Output is partially correct - 81919 call(s) of encode_bit()
20 Correct 91 ms 6664 KB Output is partially correct - 81919 call(s) of encode_bit()
21 Correct 111 ms 6844 KB Output is partially correct - 81919 call(s) of encode_bit()
22 Correct 72 ms 6396 KB Output is partially correct - 81919 call(s) of encode_bit()
23 Correct 103 ms 7120 KB Output is partially correct - 81919 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 10496 KB Output is partially correct - 81919 call(s) of encode_bit()
2 Correct 3 ms 4592 KB Output is correct - 65 call(s) of encode_bit()
3 Correct 33 ms 5596 KB Output is partially correct - 73719 call(s) of encode_bit()
4 Correct 3 ms 4580 KB Output is correct - 81 call(s) of encode_bit()
5 Correct 32 ms 5748 KB Output is partially correct - 73719 call(s) of encode_bit()
6 Correct 33 ms 5856 KB Output is partially correct - 81919 call(s) of encode_bit()
7 Correct 60 ms 6172 KB Output is partially correct - 81919 call(s) of encode_bit()
8 Correct 30 ms 5820 KB Output is partially correct - 78721 call(s) of encode_bit()
9 Correct 33 ms 5780 KB Output is partially correct - 81919 call(s) of encode_bit()
10 Correct 33 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
11 Correct 39 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
12 Correct 32 ms 5864 KB Output is partially correct - 81919 call(s) of encode_bit()
13 Correct 57 ms 6348 KB Output is partially correct - 81919 call(s) of encode_bit()
14 Correct 36 ms 5892 KB Output is partially correct - 81919 call(s) of encode_bit()
15 Correct 34 ms 5932 KB Output is partially correct - 81919 call(s) of encode_bit()
16 Correct 65 ms 6248 KB Output is partially correct - 81919 call(s) of encode_bit()
17 Correct 66 ms 6372 KB Output is partially correct - 81919 call(s) of encode_bit()
18 Correct 63 ms 6428 KB Output is partially correct - 81919 call(s) of encode_bit()
19 Correct 48 ms 6000 KB Output is partially correct - 81919 call(s) of encode_bit()
20 Correct 91 ms 6664 KB Output is partially correct - 81919 call(s) of encode_bit()
21 Correct 111 ms 6844 KB Output is partially correct - 81919 call(s) of encode_bit()
22 Correct 72 ms 6396 KB Output is partially correct - 81919 call(s) of encode_bit()
23 Correct 103 ms 7120 KB Output is partially correct - 81919 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 10496 KB Output is partially correct - 81919 call(s) of encode_bit()
2 Correct 3 ms 4592 KB Output is correct - 65 call(s) of encode_bit()
3 Correct 33 ms 5596 KB Output is partially correct - 73719 call(s) of encode_bit()
4 Correct 3 ms 4580 KB Output is correct - 81 call(s) of encode_bit()
5 Correct 32 ms 5748 KB Output is partially correct - 73719 call(s) of encode_bit()
6 Correct 33 ms 5856 KB Output is partially correct - 81919 call(s) of encode_bit()
7 Correct 60 ms 6172 KB Output is partially correct - 81919 call(s) of encode_bit()
8 Correct 30 ms 5820 KB Output is partially correct - 78721 call(s) of encode_bit()
9 Correct 33 ms 5780 KB Output is partially correct - 81919 call(s) of encode_bit()
10 Correct 33 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
11 Correct 39 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
12 Correct 32 ms 5864 KB Output is partially correct - 81919 call(s) of encode_bit()
13 Correct 57 ms 6348 KB Output is partially correct - 81919 call(s) of encode_bit()
14 Correct 36 ms 5892 KB Output is partially correct - 81919 call(s) of encode_bit()
15 Correct 34 ms 5932 KB Output is partially correct - 81919 call(s) of encode_bit()
16 Correct 65 ms 6248 KB Output is partially correct - 81919 call(s) of encode_bit()
17 Correct 66 ms 6372 KB Output is partially correct - 81919 call(s) of encode_bit()
18 Correct 63 ms 6428 KB Output is partially correct - 81919 call(s) of encode_bit()
19 Correct 48 ms 6000 KB Output is partially correct - 81919 call(s) of encode_bit()
20 Correct 91 ms 6664 KB Output is partially correct - 81919 call(s) of encode_bit()
21 Correct 111 ms 6844 KB Output is partially correct - 81919 call(s) of encode_bit()
22 Correct 72 ms 6396 KB Output is partially correct - 81919 call(s) of encode_bit()
23 Correct 103 ms 7120 KB Output is partially correct - 81919 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 10496 KB Output is partially correct - 81919 call(s) of encode_bit()
2 Correct 3 ms 4592 KB Output is correct - 65 call(s) of encode_bit()
3 Correct 33 ms 5596 KB Output is partially correct - 73719 call(s) of encode_bit()
4 Correct 3 ms 4580 KB Output is correct - 81 call(s) of encode_bit()
5 Correct 32 ms 5748 KB Output is partially correct - 73719 call(s) of encode_bit()
6 Correct 33 ms 5856 KB Output is partially correct - 81919 call(s) of encode_bit()
7 Correct 60 ms 6172 KB Output is partially correct - 81919 call(s) of encode_bit()
8 Correct 30 ms 5820 KB Output is partially correct - 78721 call(s) of encode_bit()
9 Correct 33 ms 5780 KB Output is partially correct - 81919 call(s) of encode_bit()
10 Correct 33 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
11 Correct 39 ms 5852 KB Output is partially correct - 81919 call(s) of encode_bit()
12 Correct 32 ms 5864 KB Output is partially correct - 81919 call(s) of encode_bit()
13 Correct 57 ms 6348 KB Output is partially correct - 81919 call(s) of encode_bit()
14 Correct 36 ms 5892 KB Output is partially correct - 81919 call(s) of encode_bit()
15 Correct 34 ms 5932 KB Output is partially correct - 81919 call(s) of encode_bit()
16 Correct 65 ms 6248 KB Output is partially correct - 81919 call(s) of encode_bit()
17 Correct 66 ms 6372 KB Output is partially correct - 81919 call(s) of encode_bit()
18 Correct 63 ms 6428 KB Output is partially correct - 81919 call(s) of encode_bit()
19 Correct 48 ms 6000 KB Output is partially correct - 81919 call(s) of encode_bit()
20 Correct 91 ms 6664 KB Output is partially correct - 81919 call(s) of encode_bit()
21 Correct 111 ms 6844 KB Output is partially correct - 81919 call(s) of encode_bit()
22 Correct 72 ms 6396 KB Output is partially correct - 81919 call(s) of encode_bit()
23 Correct 103 ms 7120 KB Output is partially correct - 81919 call(s) of encode_bit()