Submission #247259

#TimeUsernameProblemLanguageResultExecution timeMemory
247259hhh07The Big Prize (IOI17_prize)C++14
0 / 100
16 ms5248 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <utility> #include <set> #include <cmath> #include <cstring> #include "prize.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<ll, ll> ii; vi mem[(int)2e5 + 1]; bool done[(int)2e5 + 1]; vi pitaj(int idx){ if (done[idx]) return mem[idx]; done[idx] = true; return mem[idx] = ask(idx); } int smanji(int x, int y, int t, int maxi){ while(t*y >= t*x){ vi r = pitaj(y); if (r[0] + r[1] == 0) return -(y + 1); if (r[0] + r[1] == maxi) break; y += -t; } return y; } int bin_search(int lijevo, int beg, int end, int maxi){ if (beg > end) return -1; return -1; int l = beg, r = end; vi t; while(l < r){ int mid = (l + r)/2; t = pitaj(mid); if (t[0] + t[1] == 0) return mid; if (t[0] + t[1] == maxi){ if (lijevo - t[1]) r = mid - 1; else l = mid + 1; } else r = mid; } l = smanji(end, l, -1, maxi); if (l < 0) return - l - 1; if (mem[l][1] - mem[end + 1][1]) return bin_search(mem[l][1], l + 1, end, maxi); return -1; } int find_best(int n){ memset(done, false, sizeof done); int maxi = -1; int grupa = 460, br = n/460; int curr = 0; vi idx; for (int i = 0; i < grupa; i++){ vi res = pitaj(curr); maxi = max(maxi, res[0] + res[1]); if (res[0] + res[1] == 0) return curr; idx.push_back(curr); curr += br; if (i < (n%460)) curr++; } done[n] = true; mem[n] = {maxi, 0}; idx.push_back(n); vi r; for (int i = 0; i < idx.size() - 1; i++){ int x = idx[i], y = idx[i + 1]; int res = -1; x = smanji(y, x, -1, maxi); y = smanji(x, y, 1, maxi); if (x < 0) return - x - 1; if (y < 0) return - y - 1; if (mem[x][1] - mem[y][1]) res = bin_search(mem[x][1], x + 1, y - 1, maxi); if (res != -1) return res; } }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:88:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < idx.size() - 1; i++){
                     ~~^~~~~~~~~~~~~~~~
prize.cpp:101:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...