Submission #64267

#TimeUsernameProblemLanguageResultExecution timeMemory
64267alenam0161Saveit (IOI10_saveit)C++17
100 / 100
422 ms11512 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...