# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
152390 | 2019-09-07T20:57:50 Z | sofhiasouza | Poklon (COCI17_poklon7) | C++14 | 930 ms | 262148 KB |
#include <bits/stdc++.h> #define pb push_back using namespace std; const int maxn = 4e6+10; int n, cont, qtdz, val[maxn]; vector < int > grafo[maxn]; vector < bool >resp; void dfs(int u, int niv) { if(!grafo[u].size()) { vector < bool > aux; int flag = 0; for(int i = 31 ; i >= 0 ; i--) { if(val[u]&(1 << i)) { flag = 1; aux.pb(1); } else if(flag) aux.pb(0); } if(aux.size()+niv > resp.size()+qtdz) { resp.clear(); qtdz = niv; for(int i = 0 ; i < aux.size() ; i++) resp.pb(aux[i]); } else if(aux.size()+niv == resp.size()+qtdz) { for(int i = 0 ; i < aux.size() and i < resp.size() ; i++) { if(resp[i] > aux[i]) return; else if(resp[i] < aux[i]) { resp.clear(); qtdz = niv; for(int j = 0 ; j < aux.size() ; j++) resp.pb(aux[j]); return; } } if(aux.size() > resp.size()) { resp.clear(); qtdz = niv; for(int j = 0 ; j < aux.size() ; j++) resp.pb(aux[j]); return; } } return; } for(int i = 0 ; i < grafo[u].size() ; i++) { int v = grafo[u][i]; dfs(v, niv+1); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; cont = n; for(int i = 1 ; i <= n ; i++) { int a, b; cin >> a >> b; if(a < 0) { cont++; val[cont] = a*(-1); grafo[i].pb(cont); } else grafo[i].pb(a); if(b < 0) { cont++; val[cont] = b*(-1); grafo[i].pb(cont); } else grafo[i].pb(b); } dfs(1, 0); for(int i = 0 ; i < resp.size() ; i++) cout << resp[i]; for(int i = 0 ; i < qtdz ; i++) cout << 0; cout << "\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 88 ms | 94328 KB | Output is correct |
2 | Correct | 88 ms | 94328 KB | Output is correct |
3 | Correct | 89 ms | 94304 KB | Output is correct |
4 | Correct | 88 ms | 94328 KB | Output is correct |
5 | Correct | 88 ms | 94200 KB | Output is correct |
6 | Correct | 89 ms | 94300 KB | Output is correct |
7 | Correct | 88 ms | 94328 KB | Output is correct |
8 | Correct | 89 ms | 94220 KB | Output is correct |
9 | Correct | 89 ms | 94308 KB | Output is correct |
10 | Correct | 90 ms | 94300 KB | Output is correct |
11 | Correct | 97 ms | 95608 KB | Output is correct |
12 | Correct | 98 ms | 95480 KB | Output is correct |
13 | Correct | 134 ms | 100856 KB | Output is correct |
14 | Correct | 177 ms | 107640 KB | Output is correct |
15 | Correct | 174 ms | 98432 KB | Output is correct |
16 | Correct | 382 ms | 129144 KB | Output is correct |
17 | Correct | 784 ms | 167860 KB | Output is correct |
18 | Correct | 792 ms | 175716 KB | Output is correct |
19 | Correct | 930 ms | 161656 KB | Output is correct |
20 | Runtime error | 611 ms | 262148 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |