제출 #708162

#제출 시각아이디문제언어결과실행 시간메모리
708162Cyanmond커다란 상품 (IOI17_prize)C++17
0 / 100
6 ms1932 KiB
#include "prize.h" #include <bits/stdc++.h> /* // #include "prize.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; static const int max_q = 10000; static int n; static int query_count = 0; static vector<int> g; static vector<vector<int> > rank_count; vector<int> ask(int i) { query_count++; if(query_count > max_q) { cerr << "Query limit exceeded" << endl; exit(0); } if(i < 0 || i >= n) { cerr << "Bad index: " << i << endl; exit(0); } vector<int> res(2); res[0] = rank_count[g[i] - 1][i + 1]; res[1] = rank_count[g[i] - 1][n] - res[0]; return res; }*/ int lm(int x) { std::vector<int> val; val = {1}; while (true) { const int a = val.back(); val.push_back(a * a + 1); if (std::accumulate(val.begin(), val.end(), 0) > x) { break; } } val.pop_back(); if (val.size() == 1) { return 0; } while (true) { val[val.size() - 2]++; val[val.size() - 1] = val[val.size() - 2] * val[val.size() - 2] + 1; if (std::accumulate(val.begin(), val.end(), 0) > x) { val[val.size() - 2]--; return std::accumulate(val.begin(), --val.end(), 0); } } return -1; } std::map<int, std::vector<int>> askMemo; std::vector<int> Ask(int i) { if (askMemo.find(i) != askMemo.end()) return askMemo[i]; return askMemo[i] = ask(i); } std::vector<int> findLower(std::vector<int> ids) { auto question = [&](const int i) { return Ask(ids[i]); }; const int n = (int)ids.size(); const int limit = lm(n); std::vector<std::vector<int>> vals; for (int i = 0; i <= limit; ++i) { vals.push_back(question(i)); } int df = 0; for (const auto &vec : vals) { df = std::max(df, vec[0] + vec[1]); } std::vector<int> lws; auto relax = [&](int i, std::vector<int> &ans) { for (const auto e : lws) { if (e < i) --ans[0]; if (e > i) --ans[1]; } }; auto solve = [&](auto &&self, const int l, const int r, const int lv, const int rv) -> void { const int mid = (l + r) / 2; int lm = -1; for (int i = mid; i < r; ++i) { auto x = question(i); if (x[0] + x[1] != df) { lws.push_back(ids[i]); } else { lm = i; break; } } int rm = n + 1; for (int i = mid; i >= l; --i) { auto x = question(i); if (x[0] + x[1] != df) { lws.push_back(ids[i]); } else { rm = i; break; } } if (rm != n + 1) { auto x = question(rm); // relax(rm, x); const int newLv = lv, newRv = x[1]; if (newLv + newRv != df) { self(self, l, rm, newLv, newRv); } } if (lm != -1) { auto x = question(lm); const int newLv = x[0], newRv = rv; if (newLv + newRv != df) { self(self, lm + 1, r, newLv, newRv); } } }; solve(solve, 0, n, 0, 0); std::sort(lws.begin(), lws.end()); return lws; } int find_best(int n) { std::vector<int> ids(n); std::iota(ids.begin(), ids.end(), 0); while (ids.size() != 1) { ids = findLower(ids); } return ids[0]; }/* using namespace std; int main() { cin >> n; g.resize(n); for(int i = 0; i < n; i++) { cin >> g[i]; if(g[i] < 1) { cerr << "Invalid rank " << g[i] << " at index " << i << endl; exit(0); } } int max_rank = *max_element(g.begin(), g.end()); rank_count.resize(max_rank + 1, vector<int>(n + 1, 0)); for(int r = 0; r <= max_rank; r++) { for(int i = 1; i <= n; i++) { rank_count[r][i] = rank_count[r][i - 1]; if(g[i - 1] == r) rank_count[r][i]++; } } for(int i = 0; i <= n; i++) for(int r = 1; r <= max_rank; r++) rank_count[r][i] += rank_count[r - 1][i]; int res = find_best(n); cout << res << endl << "Query count: " << query_count << endl; return 0; }*/

컴파일 시 표준 에러 (stderr) 메시지

prize.cpp: In function 'std::vector<int> findLower(std::vector<int>)':
prize.cpp:86:10: warning: variable 'relax' set but not used [-Wunused-but-set-variable]
   86 |     auto relax = [&](int i, std::vector<int> &ans) {
      |          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...