Submission #247178

#TimeUsernameProblemLanguageResultExecution timeMemory
247178hhh07The Big Prize (IOI17_prize)C++14
0 / 100
32 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; int maxi = -1; 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){ while(y > t*x){ vi r = pitaj(y); if (r[0] + r[1] == 0) return -y; if (r[0] + r[1] == maxi) break; y--; } 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); if (l < 0) return -l; 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, 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%360) 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; y = smanji(x, y, 1); x = smanji(y, x, -1); if (x < 0) return -x; if (y < 0) return -y; if (x < y) 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:87: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]
 }
 ^
prize.cpp:71:9: warning: 'maxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int maxi, grupa = 460, br = n/460;
         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...