Submission #1286607

#TimeUsernameProblemLanguageResultExecution timeMemory
1286607SmuggingSpunA Difficult(y) Choice (BOI21_books)C++20
20 / 100
66 ms1084 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; typedef long long ll; const int lim = 1e5 + 5; ll cost[lim]; ll get(int i){ if(cost[i] != -1){ return cost[i]; } return cost[i] = skim(i); } void solve(int n, int k, ll A, int S){ memset(cost, -1, sizeof(cost)); if(S == n){ for(int i = 1; i <= n; i++){ get(i); } ll pref = accumulate(cost + 1, cost + k + 1, 0LL); if(pref > (A << 1LL)){ impossible(); return; } vector<int>ans; if(pref >= A){ for(int i = 1; i <= k; i++){ ans.push_back(i); } answer(ans); return; } ll sum = pref; for(int i = n, j = k; i > j && j > 0; i--){ ll alt = sum - cost[j] + cost[i]; if(alt <= (A << 1LL)){ if(alt >= A){ for(int t = j - 1; t > 0; t--){ ans.push_back(t); } ans.push_back(i); answer(ans); return; } pref -= cost[j--]; sum = alt; ans.push_back(i); } } impossible(); return; } if(S >= 170){ ll pref = 0; for(int i = 1; i <= k; i++){ pref += get(i); } if(pref > (A << 1LL)){ impossible(); return; } vector<int>ans; if(pref >= A){ for(int i = 1; i <= k; i++){ ans.push_back(i); } answer(ans); return; } ll sum = pref; for(int j = k, pre = n; j > 0; j--){ int low = j + 1, high = pre - 1, i = -1; while(low <= high){ int mid = (low + high) >> 1; if(sum - get(j) + get(mid) <= (A << 1LL)){ low = (i = mid) + 1; } else{ high = mid - 1; } } if(i == -1){ impossible(); } ll alt = sum - cost[j] + cost[i]; if(alt >= A){ for(int t = j - 1; t > 0; t--){ ans.push_back(t); } ans.push_back(i); answer(ans); return; } pref -= cost[j]; sum = alt; ans.push_back(pre = i); } impossible(); return; } }
#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...