Submission #64265

# Submission time Handle Problem Language Result Execution time Memory
64265 2018-08-03T19:34:22 Z alenam0161 Saveit (IOI10_saveit) C++17
100 / 100
396 ms 11392 KB
#include "grader.h"
#include "encoder.h"
#include <vector>
#include <queue>
#include <iostream>
#include <cstring>
using namespace std;
void go(int x,int pw) {
	for (int i = 0; i < pw; ++i) {
		if (x&(1 << i))encode_bit(1);
		else encode_bit(0);
	}
}
bool used[1007];
int ans[1007];
vector<int> g[1007];
int par[1007];
void dfs(int v){
    for(int to:g[v]){
        if(par[to]!=-1)continue;
        par[to]=v;
        dfs(to);
    }
}
vector<int> vl;
void add(){
    int ans=0;
    int ast=1;
    for(int i=0;i<10;++i){
        ans+=ast*vl[i];
        ast*=3;
    }
    go(ans,16);
    vl.clear();
}
void add(int x){
    vl.push_back(x+1);
    if(vl.size()==10){
        add();
    }
}
void encode(int nv, int nh, int ne, int *v1, int *v2) {
	for (int i = 0; i < ne; ++i) {
		g[v1[i]].push_back(v2[i]); g[v2[i]].push_back(v1[i]);
	}
	memset(par,-1,sizeof(par));
	par[0]=0;
	dfs(0);
	for(int i=1;i<nv;++i){
        go(par[i],10);
	}
	for (int i = 0; i < nh; ++i) {
		queue<int> q;
		memset(used, 0, sizeof(used));
		memset(ans, 0, sizeof(ans));
		used[i] = true;
		ans[i] = 0;
		q.push(i);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (int to : g[v]) {
				if (used[to])continue;
				used[to] = true;
				ans[to] = ans[v] + 1;
				q.push(to);
			}
		}
		for (int j = 0; j < nv; ++j) {
            if(j==0)continue;
            if(ans[j]==ans[par[j]])add(0);
            if(ans[j]==ans[par[j]]+1)add(1);
            if(ans[j]==ans[par[j]]-1)add(-1);
		}
	}
	if(vl.size()!=0)add();
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
int get(int pw) {
	int x = 0;
	for (int i = 0; i < pw; ++i) {
		if (decode_bit() == 1)x += (1 << i);
	}
	return x;
}
vector<int> ls;
int cx=0;
int nxt(){
    if(cx>=ls.size()){
        ls.clear();
        cx=0;
        int x=get(16);
        int ast=1;
        for(int i=0;i<10;++i)ast*=3;
        for(int i=9;i>=0;i--){
            ast/=3;
            if(ast*2<=x){
                ls.push_back(2);x-=ast*2;
            }
            else if(ast<=x){
                ls.push_back(1);x-=ast;
            }
            else{
                ls.push_back(0);
            }
        }
        reverse(ls.begin(),ls.end());
    }
    return ls[cx++]-1;
}
const int N = 1007;
vector<int> gr[N];
int parr[N];
int val[N];
bool uss[N];
void cl(int v,int ans,int lv){
    hops(lv,v,ans);
    uss[v]=true;
    for(auto to:gr[v]){
        if(uss[to]==true)continue;
        if(parr[v]==to){
            cl(to,ans-val[v],lv);
        }
        else{
            cl(to,ans+val[to],lv);
        }
    }
}
void decode(int nv, int nh) {
    parr[0]=-1;
    for(int i=1;i<nv;++i){
        int x=get(10);
        parr[i]=x;
        gr[x].push_back(i);
        gr[i].push_back(x);
    }
    for(int i=0;i<nh;++i){
        for(int j=1;j<nv;++j){
            val[j]=nxt();
        }
        memset(uss,0,sizeof(uss));
        cl(i,0,i);
    }
}

Compilation message

decoder.cpp: In function 'int nxt()':
decoder.cpp:15:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(cx>=ls.size()){
        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 396 ms 11392 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 72 call(s) of encode_bit()
3 Correct 28 ms 5488 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 4 ms 4800 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 28 ms 5564 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 41 ms 5828 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 54 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 28 ms 5488 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 31 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 31 ms 5492 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 43 ms 5716 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 30 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 88 ms 6196 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 37 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 77 ms 6112 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 71 ms 5980 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 83 ms 6312 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 55 ms 5824 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 95 ms 6548 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 94 ms 6748 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 75 ms 6200 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 104 ms 6960 KB Output is correct - 67542 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 396 ms 11392 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 72 call(s) of encode_bit()
3 Correct 28 ms 5488 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 4 ms 4800 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 28 ms 5564 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 41 ms 5828 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 54 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 28 ms 5488 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 31 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 31 ms 5492 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 43 ms 5716 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 30 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 88 ms 6196 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 37 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 77 ms 6112 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 71 ms 5980 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 83 ms 6312 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 55 ms 5824 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 95 ms 6548 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 94 ms 6748 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 75 ms 6200 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 104 ms 6960 KB Output is correct - 67542 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 396 ms 11392 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 72 call(s) of encode_bit()
3 Correct 28 ms 5488 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 4 ms 4800 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 28 ms 5564 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 41 ms 5828 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 54 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 28 ms 5488 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 31 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 31 ms 5492 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 43 ms 5716 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 30 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 88 ms 6196 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 37 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 77 ms 6112 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 71 ms 5980 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 83 ms 6312 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 55 ms 5824 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 95 ms 6548 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 94 ms 6748 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 75 ms 6200 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 104 ms 6960 KB Output is correct - 67542 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 396 ms 11392 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 72 call(s) of encode_bit()
3 Correct 28 ms 5488 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 4 ms 4800 KB Output is correct - 72 call(s) of encode_bit()
5 Correct 28 ms 5564 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 41 ms 5828 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 54 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 28 ms 5488 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 31 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 31 ms 5492 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 43 ms 5716 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 30 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 88 ms 6196 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 37 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 77 ms 6112 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 71 ms 5980 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 83 ms 6312 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 55 ms 5824 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 95 ms 6548 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 94 ms 6748 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 75 ms 6200 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 104 ms 6960 KB Output is correct - 67542 call(s) of encode_bit()