Submission #521396

#TimeUsernameProblemLanguageResultExecution timeMemory
521396pavementA Difficult(y) Choice (BOI21_books)C++17
100 / 100
2 ms320 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll pf[100005]; map<int, ll> mem; ll qry(int x) { if (mem.find(x) != mem.end()) return mem[x]; return mem[x] = skim(x); } void solve(int N, int K, ll A, int S) { int lo = 1, hi = N, ans = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (qry(mid) >= A) ans = mid, hi = mid - 1; else lo = mid + 1; } if (ans != -1 && ans < K) impossible(); if (ans != -1) { ll cum = qry(ans); vector<int> vec; for (int i = 1; i < K; i++) cum += qry(i); if (A <= cum && cum <= 2 * A) { for (int i = 1; i < K; i++) vec.push_back(i); vec.push_back(ans); answer(vec); return; } else N = ans - 1; } ll cum = 0; vector<int> vec; for (int i = 1; i <= K; i++) pf[i] = pf[i - 1] + qry(i); if (A <= pf[K] && pf[K] <= 2 * A) { for (int i = 1; i <= K; i++) vec.push_back(i); answer(vec); return; } for (int i = N; i >= N - K + 1; i--) { cum += qry(i); vec.push_back(i); if (A <= pf[K - (N - i + 1)] + cum && pf[K - (N - i + 1)] + cum <= 2 * A) { for (int j = 1; j <= K - (N - i + 1); j++) vec.push_back(j); answer(vec); return; } } impossible(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...