제출 #506084

#제출 시각아이디문제언어결과실행 시간메모리
506084aryan12A Difficult(y) Choice (BOI21_books)C++17
100 / 100
2 ms1056 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. // void solve(int N, int K, long long A, int S) { long long L = 1, R = N; long long omk = 0; long long ans[N + 1]; for(long long i = 0; i < N + 1; i++) { ans[i] = -1; } while(L <= R) { long long mid = (L + R) >> 1; ans[mid] = skim(mid); if(ans[mid] <= A) { L = mid + 1; omk = mid; } else { R = mid - 1; } } for(long long i = 1; i <= K; i++) { //cout << "i = " << i << "\n"; if(ans[i] == -1) { ans[i] = skim(i); } } //cout << "omk = " << omk << ", K = " << K << "\n"; for(long long i = omk; i > max(omk - K, 0LL); i--) { //cout << "i = " << i << "\n"; if(ans[i] == -1) { ans[i] = skim(i); } } long long value = 0; vector<int> res; set<long long> res2; for(long long i = 1; i <= K; i++) { value += ans[i]; res.push_back(i); res2.insert(i); } if(value >= A && value <= 2LL * A) { answer(res); return; } long long cnt = 1; for(long long i = omk; i > max(omk - K, 0LL); i--) { if(res2.count(i)) continue; res2.erase(cnt); res2.insert(i); res.erase(res.begin()); res.push_back(i); value -= ans[cnt]; value += ans[i]; cnt++; if(value >= A && value <= 2LL * A) { answer(res); return; } } if(omk == N || omk < K + 1) { impossible(); return; } ans[omk + 1] = skim(omk + 1); res.clear(); value = 0; for(long long i = 1; i < K; i++) { res.push_back(i); value += ans[i]; } res.push_back(omk + 1); value += ans[omk + 1]; if(value >= A && value <= 2LL * A) { answer(res); 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...