제출 #714912

#제출 시각아이디문제언어결과실행 시간메모리
714912fadi57A Difficult(y) Choice (BOI21_books)C++14
100 / 100
1 ms324 KiB
#include <bits/stdc++.h> #include "books.h" //~ #include "grader.cpp" using namespace std; #define ll long long map <int, ll> mp; ll ask(int idx){ if(mp.count(idx)) return mp[idx]; return mp[idx] = skim(idx); } void solve(int N, int K, long long A, int S){ ll sum = 0; set <int> cur; for(int i = 1 ; i <= K ; i++){ sum += ask(i); cur.insert(i); } if(A <= sum && sum <= 2 * A){ answer(vector <int>(cur.begin(), cur.end())); return; } if(N == K || sum > 2 * A) impossible(); sum -= ask(K); int l = K + 1, r = N; while(l <= r){ int mid = (l + r) / 2; if(sum + ask(mid) < A) l = mid + 1; else r = mid - 1; } if(l <= N && A <= sum + ask(l) && sum + ask(l) <= 2 * A){ cur.erase(K); cur.insert(l); answer(vector <int>(cur.begin(), cur.end())); return; } sum += ask(K); int g = 1, h = l - 1; for(int i = 0 ; i < K ; i++){ cur.erase(g); cur.insert(h); sum -= ask(g); sum += ask(h); if(A <= sum && sum <= 2 * A){ answer(vector <int>(cur.begin(), cur.end())); return; } g++; h--; } 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...