제출 #470303

#제출 시각아이디문제언어결과실행 시간메모리
470303Haruto810198A Difficult(y) Choice (BOI21_books)C++17
0 / 100
1 ms200 KiB
#include <bits/stdc++.h> #include "books.h" #define ll long long #define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d)) #define vi vector<int> #define pb push_back using namespace std; // // --- Sample implementation for the task books --- // // To compile this program with the sample grader, place: // books.h books_sample.cpp sample_grader.cpp // in a single folder and run: // g++ books_sample.cpp sample_grader.cpp // in this folder. // const int MAX = 100010; ll arr[MAX]; vector<int> res; int query(int id){ if(arr[id] == 0){ arr[id] = skim(id); } return arr[id]; } bool solve_for_small_items(int small_cnt, int K, int A){ vi pref, suf; if(small_cnt < K){ return 0; } FOR(i, 1, K, 1){ pref.pb(i); suf.pb(small_cnt + 1 - i); } FOR(i, 0, K, 1){ int sum = 0; res.clear(); FOR(j, 0, i-1, 1){ sum += query(pref[j]); res.pb(pref[j]); } FOR(j, 0, K-i-1, 1){ sum += query(suf[j]); res.pb(suf[j]); } if(A <= sum and sum <= 2*A){ return 1; } } return 0; } void solve(int N, int K, ll A, int Q){ // find first large item int first_large_item; int L = 1, R = N, mid; if(query(N) < A){ first_large_item = N + 1; } else{ while(L < R){ mid = (L + R) / 2; if(query(mid) >= A) R = mid; else L = mid + 1; } first_large_item = L; } // all small items if(solve_for_small_items(first_large_item - 1, K, A)){ answer(res); return; } // if no solution for all small items: // 1 large item if(first_large_item == N + 1){ // no large item impossible(); return; } if(first_large_item < K){ // not enough small items impossible(); return; } int sum = 0; res.clear(); FOR(i, 1, K-1, 1){ // solution for 1 large item and K-1 small items sum += query(i); res.pb(i); } sum += query(first_large_item); res.pb(first_large_item); if(A <= sum and sum <= 2*A){ answer(res); } else{ 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...