# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
946278 | 2024-03-14T13:17:15 Z | Pikachu | 커다란 상품 (IOI17_prize) | C++17 | 1 ms | 2032 KB |
#include <bits/stdc++.h> #include "prize.h" using namespace std; template<typename T> inline bool maxi(T &x, const T &val) { if (x < val) return x = val, true; return false; } template<typename T> inline bool mini(T &x, const T &val) { if (x > val) return x = val, true; return false; } map<int,pair<int,int> > mp[500]; int RandInt(int l, int r) { int ans = 0; for (int i = 0; i < 2; i++) { ans = (ans << 15) | (rand() & ((1 << 15) - 1)); } return ans % (r - l + 1) + l; } const int maxn = 2e5 + 10; pair<int,int> dak[maxn]; bool done; int res; pair<int,int> myask(int x) { if (done) return make_pair(-1, -1); if (dak[x].first != -1) return dak[x]; vector<int> tmp = ask(x - 1); if (tmp[0] + tmp[1] == 0) { res = x - 1; done = true; } dak[x] = make_pair(tmp[0], tmp[1]); mp[tmp[0] + tmp[1]][x] = dak[x]; return dak[x]; } int find_best(int n) { srand(time(0)); memset(dak, -1, sizeof dak); int maxx = 0; int test = 10; while (test--) { int x = RandInt(1, n); pair<int,int> tmp = myask(x); maxi(maxx, tmp.first + tmp.second); } int cur = 1; while (!done) { pair<int,int> tmp = myask(cur); if (tmp.first + tmp.second != maxx) cur++; else break; } cerr << cur << endl; while (!done) { if (myask(cur).second == 0) break; if (myask(cur).second == n - cur) { for (int i = cur + 1; i <= n; i++) { myask(i); } break; } auto it = mp[maxx].upper_bound(cur); int nex = n; if (it != mp[maxx].end()) { if (it -> second.second == mp[maxx][cur].second) { cur = nex; continue; } nex = it -> first; } int mid = (cur + nex) >> 1; while (true) { pair<int,int> tmp = myask(mid); if (tmp.first + tmp.second != maxx) mid--; else break; } if (mid == cur) { mid = (cur + nex) >> 1; while (true) { pair<int,int> tmp = myask(mid); if (tmp.first + tmp.second != maxx) mid++; else break; } if (mid == nex) { cur = nex; } else { cur = mid; } continue; } } return res; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2032 KB | answer is not correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2028 KB | answer is not correct |
2 | Halted | 0 ms | 0 KB | - |