Submission #523519

#TimeUsernameProblemLanguageResultExecution timeMemory
523519fatemetmhrA Difficult(y) Choice (BOI21_books)C++17
0 / 100
2 ms2632 KiB
// Be name khoda // #include <bits/stdc++.h> #include "books.h" using namespace std; typedef long long ll; const int maxn5 = 3e5 + 10; const int lg = 20; #define pb push_back #define se second #define fi first // // --- 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. // int n, k, s; ll A, have; ll a[maxn5]; inline bool check(int pre){ ll have = 0; if(a[pre + 1] == -1) a[pre + 1] = skim(pre + 1); for(int i = 1; i <= pre + 1; i++) have += a[i]; for(int i = n - (k - 1 - pre) + 1; i <= n; i++) have += a[i]; return have >= A; } inline bool ok(int id){ return have + skim(id) <= A; } void solve(int N, int K, long long AA, int S) { n = N; k = K; s = S; A = AA; memset(a, -1, sizeof a); for(int i = 1; i <= k; i++) a[i] = skim(i); for(int i = n - k + 1; i <= n; i++) a[i] = skim(i); int lo = 0, hi = k; while(hi - lo > 1){ int mid = (lo + hi) >> 1; if(check(mid)) lo = mid; else hi = mid; } if(lo == 0){ have = 0; for(int i = n - k + 1; i <= n; i++) have += a[i]; if(have < A) impossible(); } if(lo == k){ have = 0; for(int i = 1; i <= k; i++) have += a[i]; if(have > 2 * A) impossible(); } have = 0; for(int i = 1; i <= lo; i++) have += a[i]; for(int i = n - (k - 1 - lo) + 1; i <= n; i++) have += a[i]; int l = lo + 1, r = n - (k - 1 - lo) + 1; while(r - l > 1){ int mid = (l + r) >> 1; if(ok(mid)) l = mid; else r = mid; } vector <int> ret; ret.clear(); for(int i = 1; i <= lo; i++) ret.pb(i); ret.pb(l); for(int i = n - (k - 1 - lo) + 1; i <= n; i++) ret.pb(i); answer(ret); if (skim(2) == 42) { impossible(); } else { answer({1, 3}); } }
#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...