# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41861 | 2018-02-21T16:05:14 Z | rahasia | The Big Prize (IOI17_prize) | C++14 | 355 ms | 5256 KB |
#include "prize.h" #include <bits/stdc++.h> using namespace std; int find_best(int n) { int awal,akhir,kiri,kanan,pos,pos1,pos2,aa,bb,itr; int ans; int coba[200009]; vector <int> a; vector <int> cand,cand2; bool sudah[200009]; for(itr=0;itr<n;++itr) { cand.push_back(itr); } ans = -1; kiri = 0; kanan = n-1; while(true) { if(ans != -1) { return ans; break; } for(itr=0;itr<cand.size();++itr) { sudah[itr] = false; } awal = 0; akhir = cand.size()-1; pos = (akhir-awal)/2; pos1 = pos; pos2 = pos; while(pos1 > 0) { a = ask(cand[pos1]); sudah[pos1] = true; if(a[0] == 0 && a[1] == 0) { ans = cand[pos1]; return ans; break; } else if(a[0] == 0) { kiri = max(kiri, cand[pos1]); break; } else if(a[1] == 0) { kanan = min(kanan, cand[pos1]); } pos1 = pos1/2; } a = ask(cand[0]); sudah[0] = true; if(a[0] == 0 && a[1] == 0) { ans = cand[pos1]; return ans; break; } else if(a[0] == 0) { kiri = max(kiri, cand[0]); } else if(a[1] == 0) { kanan = min(kanan, cand[0]); } while(pos2 < akhir-1) { a = ask(cand[pos2]); sudah[pos2] = true; if(a[0] == 0 && a[1] == 0) { ans = cand[pos2]; return ans; break; } else if(a[0] == 0) { kiri = max(kiri, cand[pos2]); } else if(a[1] == 0) { kanan = min(kanan, cand[pos2]); break; } pos2 = pos2 + (akhir-pos2)/2; } a = ask(cand[akhir-1]); sudah[akhir-1] = true; if(a[0] == 0 && a[1] == 0) { ans = cand[akhir-1]; return ans; break; } else if(a[0] == 0) { kiri = max(kiri, cand[akhir-1]); } else if(a[1] == 0) { kanan = min(kanan, cand[akhir-1]); } a = ask(cand[akhir]); sudah[akhir] = true; if(a[0] == 0 && a[1] == 0) { ans = cand[akhir]; return ans; break; } else if(a[0] == 0) { kiri = max(kiri, cand[akhir]); } else if(a[1] == 0) { kanan = min(kanan, cand[akhir]); } for(itr=0;itr<cand.size();++itr) { if(sudah[itr] == false && cand[itr] >= kiri && cand[itr] <= kanan) { cand2.push_back(cand[itr]); } } cand.clear(); for(itr=0;itr<cand2.size();++itr) { cand.push_back(cand2[itr]); } cand2.clear(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3716 KB | Output is correct |
2 | Correct | 4 ms | 3720 KB | Output is correct |
3 | Correct | 0 ms | 3716 KB | Output is correct |
4 | Correct | 0 ms | 3716 KB | Output is correct |
5 | Correct | 4 ms | 3716 KB | Output is correct |
6 | Correct | 2 ms | 3716 KB | Output is correct |
7 | Correct | 4 ms | 3720 KB | Output is correct |
8 | Correct | 1 ms | 3716 KB | Output is correct |
9 | Correct | 3 ms | 3716 KB | Output is correct |
10 | Correct | 0 ms | 3712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3712 KB | Output is correct |
2 | Correct | 1 ms | 3720 KB | Output is correct |
3 | Correct | 0 ms | 3720 KB | Output is correct |
4 | Correct | 0 ms | 3712 KB | Output is correct |
5 | Correct | 0 ms | 3720 KB | Output is correct |
6 | Correct | 2 ms | 3712 KB | Output is correct |
7 | Correct | 3 ms | 3720 KB | Output is correct |
8 | Correct | 4 ms | 3712 KB | Output is correct |
9 | Correct | 2 ms | 3720 KB | Output is correct |
10 | Correct | 2 ms | 3712 KB | Output is correct |
11 | Incorrect | 355 ms | 5256 KB | Incorrect |
12 | Halted | 0 ms | 0 KB | - |