답안 #718866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718866 2023-04-05T03:06:15 Z lam 저장 (Saveit) (IOI10_saveit) C++14
75 / 100
219 ms 10652 KB
#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n;
int par[maxn];
int d[36][maxn];
vector <int> adj[maxn];

void bfs(int rt, bool keep)
{
    queue<int> q;
    fill_n(d[rt],n,-1);
    d[rt][rt] = 0;
    q.push(rt);
    if (keep) par[rt] = rt;
    while (!q.empty())
    {
        int u=q.front(); q.pop();
        for (int v:adj[u])
            if (d[rt][v] == -1)
        {
            d[rt][v] = d[rt][u] + 1;
            if (keep) par[v] = u;
            q.push(v);
        }
    }
}

inline bool checkbit(int i, int j)
{
    return i>>j&1;
}

void encode(int nv, int nh, int ne, int *v1, int *v2){
    n=nv;
    for (int i=0; i<n; i++) adj[i].clear();
    for (int i=0; i<ne; i++)
    {
        int u=v1[i]; int v=v2[i];
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i=0; i<nh; i++) bfs(i,(i==0));
    for (int i=0; i<n; i++)
    {

        for (int j=0; j<10; j++)
        {
//            cerr<<i<<' '<<j<<' '<<par[i]<<" : "<<checkbit(par[i],j)<<endl;
            encode_bit(checkbit(par[i],j));
        }
    }
//    for (int i=0; i<n; i++) cerr<<d[0][i]<<" : "; cerr<<endl;
//    for (int i=0; i<n; i++) cerr<<d[1][i]<<" : "; cerr<<endl;
    par[n]=par[n+1]=par[n+2]=0;
    for (int rt=1; rt<nh; rt++)
        for (int i=1; i<n; i+=3)
    {
        int u,v;
        u=i; v=par[i];
//        cerr<<u<<" - "<<v<<endl;
        int t1 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
        u=i+1; v=par[i+1];
        int t2 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
        u=i+2; v=par[i+2];
        int t3 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
        int T = t1+t2*3+t3*9;
//        cerr<<t1<<" & "<<t2<<" & "<<t3<<endl;
        for (int z=0; z<=5; z++) encode_bit(checkbit(T,z));
    }
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int _n,_rt;
vector <int> _adj[maxn];
int _par[maxn];
int _d[maxn],_t[maxn],_ans[maxn];
void _BFS()
{
    queue<int> q;
    fill_n(_d,_n,-1);
    _d[0] = 0;
    q.push(0);
    while (!q.empty())
    {
        int u=q.front(); q.pop();
        for (int v:_adj[u])
            if (_d[v]==-1)
        {
            _d[v]=_d[u]+1;
            q.push(v);
        }
    }
}
void dfs(int x, int p)
{
    for (int i:_adj[x])
        if (i!=p)
    {
        if (_t[i]==0) _ans[i]=_ans[x];
        else if (_t[i]==1) _ans[i]=_ans[x]+1;
        else _ans[i]=_ans[x]-1;
        dfs(i,x);
    }
}
void decode(int nv, int nh) {
    _n=nv; _rt = 0;
//    cerr<<nv<<' '<<nh<<endl;
    for (int i=0; i<_n; i++)
    {
        int x=0;
        for (int j=0; j<10; j++) if (decode_bit()) x|=(1<<j);
        _par[i] = x;
        _adj[_par[i]].push_back(i);
//        cerr<<_par[i]<<" -> "<<i<<endl;
    }
    _BFS();
//    for (int i=0; i<_n; i++) cerr<<_d[i]<<' '; cerr<<endl;
    for (int i=0; i<_n; i++) hops(_rt,i,_d[i]);
    for (int st = 1; st<nh; st++)
    {
//        cerr<<st<<endl;
        for (int i=1; i<_n; i+=3)
        {
            int T = 0;
            for (int z=0; z<=5; z++) if (decode_bit()) T |= (1<<z);
            int t1 = T%3; T/=3;
            int t2 = T%3; T/=3;
            int t3 = T%3; T/=3;
            _t[i]=t1; _t[i+1]=t2; _t[i+2]=t3;
        }
//        for (int i=1; i<_n; i++) cerr<<_t[i]<<' '; cerr<<endl;
        _ans[0] = _d[st];
        dfs(0,0);
//        for (int i=0; i<_n; i++) cerr<<_ans[i]<<' '; cerr<<endl;
        for (int i=0; i<_n; i++) hops(st,i,_ans[i]);
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 10652 KB Output is partially correct - 79930 call(s) of encode_bit()
2 Correct 1 ms 4604 KB Output is correct - 74 call(s) of encode_bit()
3 Correct 20 ms 5600 KB Output is partially correct - 72000 call(s) of encode_bit()
4 Correct 2 ms 4612 KB Output is correct - 98 call(s) of encode_bit()
5 Correct 23 ms 5688 KB Output is partially correct - 72000 call(s) of encode_bit()
6 Correct 24 ms 5764 KB Output is partially correct - 79930 call(s) of encode_bit()
7 Correct 36 ms 5964 KB Output is partially correct - 79930 call(s) of encode_bit()
8 Correct 22 ms 5644 KB Output is partially correct - 76810 call(s) of encode_bit()
9 Correct 24 ms 5608 KB Output is partially correct - 79930 call(s) of encode_bit()
10 Correct 27 ms 5620 KB Output is partially correct - 79930 call(s) of encode_bit()
11 Correct 30 ms 5736 KB Output is partially correct - 79930 call(s) of encode_bit()
12 Correct 23 ms 5680 KB Output is partially correct - 79930 call(s) of encode_bit()
13 Correct 45 ms 6188 KB Output is partially correct - 79930 call(s) of encode_bit()
14 Correct 26 ms 5720 KB Output is partially correct - 79930 call(s) of encode_bit()
15 Correct 25 ms 5696 KB Output is partially correct - 79930 call(s) of encode_bit()
16 Correct 49 ms 6080 KB Output is partially correct - 79930 call(s) of encode_bit()
17 Correct 38 ms 6108 KB Output is partially correct - 79930 call(s) of encode_bit()
18 Correct 61 ms 6348 KB Output is partially correct - 79930 call(s) of encode_bit()
19 Correct 34 ms 6028 KB Output is partially correct - 79930 call(s) of encode_bit()
20 Correct 51 ms 6716 KB Output is partially correct - 79930 call(s) of encode_bit()
21 Correct 62 ms 6772 KB Output is partially correct - 79930 call(s) of encode_bit()
22 Correct 43 ms 6164 KB Output is partially correct - 79930 call(s) of encode_bit()
23 Correct 68 ms 6980 KB Output is partially correct - 79930 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 10652 KB Output is partially correct - 79930 call(s) of encode_bit()
2 Correct 1 ms 4604 KB Output is correct - 74 call(s) of encode_bit()
3 Correct 20 ms 5600 KB Output is partially correct - 72000 call(s) of encode_bit()
4 Correct 2 ms 4612 KB Output is correct - 98 call(s) of encode_bit()
5 Correct 23 ms 5688 KB Output is partially correct - 72000 call(s) of encode_bit()
6 Correct 24 ms 5764 KB Output is partially correct - 79930 call(s) of encode_bit()
7 Correct 36 ms 5964 KB Output is partially correct - 79930 call(s) of encode_bit()
8 Correct 22 ms 5644 KB Output is partially correct - 76810 call(s) of encode_bit()
9 Correct 24 ms 5608 KB Output is partially correct - 79930 call(s) of encode_bit()
10 Correct 27 ms 5620 KB Output is partially correct - 79930 call(s) of encode_bit()
11 Correct 30 ms 5736 KB Output is partially correct - 79930 call(s) of encode_bit()
12 Correct 23 ms 5680 KB Output is partially correct - 79930 call(s) of encode_bit()
13 Correct 45 ms 6188 KB Output is partially correct - 79930 call(s) of encode_bit()
14 Correct 26 ms 5720 KB Output is partially correct - 79930 call(s) of encode_bit()
15 Correct 25 ms 5696 KB Output is partially correct - 79930 call(s) of encode_bit()
16 Correct 49 ms 6080 KB Output is partially correct - 79930 call(s) of encode_bit()
17 Correct 38 ms 6108 KB Output is partially correct - 79930 call(s) of encode_bit()
18 Correct 61 ms 6348 KB Output is partially correct - 79930 call(s) of encode_bit()
19 Correct 34 ms 6028 KB Output is partially correct - 79930 call(s) of encode_bit()
20 Correct 51 ms 6716 KB Output is partially correct - 79930 call(s) of encode_bit()
21 Correct 62 ms 6772 KB Output is partially correct - 79930 call(s) of encode_bit()
22 Correct 43 ms 6164 KB Output is partially correct - 79930 call(s) of encode_bit()
23 Correct 68 ms 6980 KB Output is partially correct - 79930 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 10652 KB Output is partially correct - 79930 call(s) of encode_bit()
2 Correct 1 ms 4604 KB Output is correct - 74 call(s) of encode_bit()
3 Correct 20 ms 5600 KB Output is partially correct - 72000 call(s) of encode_bit()
4 Correct 2 ms 4612 KB Output is correct - 98 call(s) of encode_bit()
5 Correct 23 ms 5688 KB Output is partially correct - 72000 call(s) of encode_bit()
6 Correct 24 ms 5764 KB Output is partially correct - 79930 call(s) of encode_bit()
7 Correct 36 ms 5964 KB Output is partially correct - 79930 call(s) of encode_bit()
8 Correct 22 ms 5644 KB Output is partially correct - 76810 call(s) of encode_bit()
9 Correct 24 ms 5608 KB Output is partially correct - 79930 call(s) of encode_bit()
10 Correct 27 ms 5620 KB Output is partially correct - 79930 call(s) of encode_bit()
11 Correct 30 ms 5736 KB Output is partially correct - 79930 call(s) of encode_bit()
12 Correct 23 ms 5680 KB Output is partially correct - 79930 call(s) of encode_bit()
13 Correct 45 ms 6188 KB Output is partially correct - 79930 call(s) of encode_bit()
14 Correct 26 ms 5720 KB Output is partially correct - 79930 call(s) of encode_bit()
15 Correct 25 ms 5696 KB Output is partially correct - 79930 call(s) of encode_bit()
16 Correct 49 ms 6080 KB Output is partially correct - 79930 call(s) of encode_bit()
17 Correct 38 ms 6108 KB Output is partially correct - 79930 call(s) of encode_bit()
18 Correct 61 ms 6348 KB Output is partially correct - 79930 call(s) of encode_bit()
19 Correct 34 ms 6028 KB Output is partially correct - 79930 call(s) of encode_bit()
20 Correct 51 ms 6716 KB Output is partially correct - 79930 call(s) of encode_bit()
21 Correct 62 ms 6772 KB Output is partially correct - 79930 call(s) of encode_bit()
22 Correct 43 ms 6164 KB Output is partially correct - 79930 call(s) of encode_bit()
23 Correct 68 ms 6980 KB Output is partially correct - 79930 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 10652 KB Output is partially correct - 79930 call(s) of encode_bit()
2 Correct 1 ms 4604 KB Output is correct - 74 call(s) of encode_bit()
3 Correct 20 ms 5600 KB Output is partially correct - 72000 call(s) of encode_bit()
4 Correct 2 ms 4612 KB Output is correct - 98 call(s) of encode_bit()
5 Correct 23 ms 5688 KB Output is partially correct - 72000 call(s) of encode_bit()
6 Correct 24 ms 5764 KB Output is partially correct - 79930 call(s) of encode_bit()
7 Correct 36 ms 5964 KB Output is partially correct - 79930 call(s) of encode_bit()
8 Correct 22 ms 5644 KB Output is partially correct - 76810 call(s) of encode_bit()
9 Correct 24 ms 5608 KB Output is partially correct - 79930 call(s) of encode_bit()
10 Correct 27 ms 5620 KB Output is partially correct - 79930 call(s) of encode_bit()
11 Correct 30 ms 5736 KB Output is partially correct - 79930 call(s) of encode_bit()
12 Correct 23 ms 5680 KB Output is partially correct - 79930 call(s) of encode_bit()
13 Correct 45 ms 6188 KB Output is partially correct - 79930 call(s) of encode_bit()
14 Correct 26 ms 5720 KB Output is partially correct - 79930 call(s) of encode_bit()
15 Correct 25 ms 5696 KB Output is partially correct - 79930 call(s) of encode_bit()
16 Correct 49 ms 6080 KB Output is partially correct - 79930 call(s) of encode_bit()
17 Correct 38 ms 6108 KB Output is partially correct - 79930 call(s) of encode_bit()
18 Correct 61 ms 6348 KB Output is partially correct - 79930 call(s) of encode_bit()
19 Correct 34 ms 6028 KB Output is partially correct - 79930 call(s) of encode_bit()
20 Correct 51 ms 6716 KB Output is partially correct - 79930 call(s) of encode_bit()
21 Correct 62 ms 6772 KB Output is partially correct - 79930 call(s) of encode_bit()
22 Correct 43 ms 6164 KB Output is partially correct - 79930 call(s) of encode_bit()
23 Correct 68 ms 6980 KB Output is partially correct - 79930 call(s) of encode_bit()