Submission #64267

# Submission time Handle Problem Language Result Execution time Memory
64267 2018-08-03T19:45:55 Z alenam0161 Saveit (IOI10_saveit) C++17
100 / 100
422 ms 11512 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<15;++i){
        ans+=ast*vl[i];
        ast*=3;
    }
    go(ans,24);
    vl.clear();
}
void add(int x){
    vl.push_back(x+1);
    if(vl.size()==15){
        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(24);
        int ast=1;
        for(int i=0;i<15;++i)ast*=3;
        for(int i=14;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 422 ms 11512 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 28 ms 5436 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 7 ms 4672 KB Output is correct - 88 call(s) of encode_bit()
5 Correct 37 ms 5704 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 43 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 71 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 30 ms 5636 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 33 ms 5584 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 33 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 35 ms 5820 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 31 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 83 ms 6364 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5488 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 35 ms 5624 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 68 ms 6136 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 56 ms 6028 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 60 ms 6412 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 43 ms 5948 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 88 ms 6568 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 103 ms 6668 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 78 ms 6100 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 86 ms 6908 KB Output is correct - 67542 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 422 ms 11512 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 28 ms 5436 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 7 ms 4672 KB Output is correct - 88 call(s) of encode_bit()
5 Correct 37 ms 5704 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 43 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 71 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 30 ms 5636 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 33 ms 5584 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 33 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 35 ms 5820 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 31 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 83 ms 6364 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5488 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 35 ms 5624 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 68 ms 6136 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 56 ms 6028 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 60 ms 6412 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 43 ms 5948 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 88 ms 6568 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 103 ms 6668 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 78 ms 6100 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 86 ms 6908 KB Output is correct - 67542 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 422 ms 11512 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 28 ms 5436 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 7 ms 4672 KB Output is correct - 88 call(s) of encode_bit()
5 Correct 37 ms 5704 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 43 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 71 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 30 ms 5636 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 33 ms 5584 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 33 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 35 ms 5820 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 31 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 83 ms 6364 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5488 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 35 ms 5624 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 68 ms 6136 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 56 ms 6028 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 60 ms 6412 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 43 ms 5948 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 88 ms 6568 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 103 ms 6668 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 78 ms 6100 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 86 ms 6908 KB Output is correct - 67542 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 422 ms 11512 KB Output is correct - 67542 call(s) of encode_bit()
2 Correct 7 ms 4672 KB Output is correct - 64 call(s) of encode_bit()
3 Correct 28 ms 5436 KB Output is correct - 60782 call(s) of encode_bit()
4 Correct 7 ms 4672 KB Output is correct - 88 call(s) of encode_bit()
5 Correct 37 ms 5704 KB Output is correct - 60782 call(s) of encode_bit()
6 Correct 43 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
7 Correct 71 ms 6076 KB Output is correct - 67542 call(s) of encode_bit()
8 Correct 30 ms 5636 KB Output is correct - 64896 call(s) of encode_bit()
9 Correct 33 ms 5584 KB Output is correct - 67542 call(s) of encode_bit()
10 Correct 33 ms 5564 KB Output is correct - 67542 call(s) of encode_bit()
11 Correct 35 ms 5820 KB Output is correct - 67542 call(s) of encode_bit()
12 Correct 31 ms 5436 KB Output is correct - 67542 call(s) of encode_bit()
13 Correct 83 ms 6364 KB Output is correct - 67542 call(s) of encode_bit()
14 Correct 32 ms 5488 KB Output is correct - 67542 call(s) of encode_bit()
15 Correct 35 ms 5624 KB Output is correct - 67542 call(s) of encode_bit()
16 Correct 68 ms 6136 KB Output is correct - 67542 call(s) of encode_bit()
17 Correct 56 ms 6028 KB Output is correct - 67542 call(s) of encode_bit()
18 Correct 60 ms 6412 KB Output is correct - 67542 call(s) of encode_bit()
19 Correct 43 ms 5948 KB Output is correct - 67542 call(s) of encode_bit()
20 Correct 88 ms 6568 KB Output is correct - 67542 call(s) of encode_bit()
21 Correct 103 ms 6668 KB Output is correct - 67542 call(s) of encode_bit()
22 Correct 78 ms 6100 KB Output is correct - 67542 call(s) of encode_bit()
23 Correct 86 ms 6908 KB Output is correct - 67542 call(s) of encode_bit()