Submission #139417

#TimeUsernameProblemLanguageResultExecution timeMemory
139417wilwxkHighway Tolls (IOI18_highway)C++14
0 / 100
532 ms262148 KiB
#include "highway.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=9e4+5; vector<int> g[MAXN], config; vector<int> bons; int aresta[MAXN*2][2]; int pid[MAXN], lvl[MAXN]; bool ruim[MAXN]; int n, m, x, y; ll tam; void pinta(int ini, int fim, int k) { if(fim<ini||ini<0) return; for(int i=ini; i<=fim; i++) config[pid[bons[i]]]=k; } void dfs(int cur, int pp, int d) { pid[cur]=pp; lvl[cur]=d; for(auto vid : g[cur]) { if(vid==pp) continue; int viz= aresta[vid][ aresta[vid][0]==cur ]; dfs(viz, vid, d+1); } } // int divide(int cur) { // return 1; // for(auto vid : g[cur]) { // } // } // int conquer(int cur) { // } void acaba() { if(bons.size()==2) { answer(bons[0], bons[1]); return; } // for(auto cur : bons) printf("bb %d (%d)\n", cur, pid[cur]); cout << endl; vector<int> aux; int mid=(bons.size()+1)/2; pinta(0, mid, 1); ll val=ask(config); // for(auto cur : config) printf("%d ", cur); printf(">> %d %lld %lld\n", mid, val, tam); if(val==tam) { for(int i=mid+1; i<bons.size(); i++) aux.push_back(bons[i]); bons.clear(); for(auto cur : aux) bons.push_back(cur); } else if(val==tam+2*(y-x)) { for(int i=0; i<=mid; i++) aux.push_back(bons[i]); bons.clear(); for(auto cur : aux) bons.push_back(cur); } else { pinta(0, mid, 0); random_shuffle(bons.begin(), bons.end()); } pinta(0, mid, 0); acaba(); } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { n=N; m=U.size(); x=A; y=B; for(int i=0; i<m; i++) { int a=U[i]; int b=V[i]; aresta[i][0]=a; aresta[i][1]=b; g[a].push_back(i); g[b].push_back(i); config.push_back(0); } dfs(0, -1, 0); tam=ask(config); for(int i=1; i<n; i++) { if(lvl[i]==tam/x) bons.push_back(i); else ruim[i]=1; } for(int i=0; i<n; i++) { if(ruim[i]) { dfs(i, -1, 0); break; } } bons.push_back(0); fill(config.begin(), config.end(), 0); srand(time(0)+n+m); random_shuffle(bons.begin(), bons.end()); acaba(); }

Compilation message (stderr)

highway.cpp: In function 'void acaba()':
highway.cpp:54:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=mid+1; i<bons.size(); i++) aux.push_back(bons[i]);
                      ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...