제출 #528891

#제출 시각아이디문제언어결과실행 시간메모리
528891OttoTheDinoA Difficult(y) Choice (BOI21_books)C++17
10 / 100
1 ms332 KiB
#include <bits/stdc++.h> #include "books.h" 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. // #define rep(i,s,e) for (ll i = s; i <= e; ++i) #define all(a) a.begin(), a.end() typedef long long ll; const ll mx = 2e5; ll x[mx]; ll get (int i) { if (!x[i]) x[i] = skim(i); return x[i]; } void solve(int n, int k, long long a, int S) { if (k==1) { int lo = 1, hi = n+1; while (lo<hi) { int mid = (lo+hi)/2; if (get(mid)>=a) hi = mid; else lo = mid+1; } if (hi==n+1 || get(lo)>2*a) impossible(); else answer({lo}); return; } vector<int> ans(k); iota(all(ans),1); ll s = 0; rep (i,1,k) { x[i] = get(i); s += x[i]; } if (s>2*a) impossible(); else if (s>=a) { answer(ans); return; } else { ll lo = k+1, hi = n+1; while (lo<hi) { ll mid = (lo+hi)/2; x[mid] = get(mid); if (x[mid]>=a) hi = mid; else lo = mid+1; } if (lo!=n+1) { if (s+x[lo]-x[k]<=2*n) { ans[k-1] = lo; answer(ans); return; } } n = --lo; rep (i,1,k) { x[n-i+1] = get(n-i+1); s += x[n-i+1] - x[k-i+1]; ans[k-i] = n-i+1; if (s>=a) { answer(ans); 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...