Submission #730504

#TimeUsernameProblemLanguageResultExecution timeMemory
730504nguyentunglamA Difficult(y) Choice (BOI21_books)C++17
45 / 100
1 ms276 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; const int N = 1e5 + 10; long long a[N]; // // --- 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) { // TODO implement this function int l = 1, r = n; long long v = 0; int p = n + 1; while (l <= r) { int mid = l + r >> 1; long long tmp = skim(mid); if (tmp >= A) { v = tmp; p = mid; r = mid - 1; } else l = mid + 1; } for(int i = 1; i <= min(k, p - 1); i++) a[i] = skim(i); for(int i = 1; i <= k - 1; i++) v += a[i]; vector<int> ret; if (p <= n && k - 1 < p && v <= A * 2) { for(int i = 1; i <= k - 1; i++) ret.push_back(i); ret.push_back(p); answer(ret); } long long cur = 0; for(int i = k; i >= 1; i--) { ret.push_back(i); cur += a[i]; } if (cur > A * 2) impossible(); else if (cur >= A) answer(ret); else { --p; vector<int> add; while (p > k) { cur = cur - a[ret.back()] + skim(p); ret.pop_back(); add.push_back(p); p--; if (cur >= A) { for(int &j : add) ret.push_back(j); answer(ret); return; } } impossible(); } }

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:24:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |         int mid = l + r >> 1;
      |                   ~~^~~
#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...