Submission #697931

#TimeUsernameProblemLanguageResultExecution timeMemory
697931_martynasA Difficult(y) Choice (BOI21_books)C++14
0 / 100
12 ms324 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 F first #define S second #define PB push_back #define all(a) (a).begin(), (a).end() using ll = long long; void solve(int N, int K, long long A, int S) { vector<pair<ll, int>> known; if(S >= N) { for(int i = 1; i <= N; i++) { known.PB({skim(i), i}); } vector<pair<ll, int>> consider; for(int i = 1; i <= K; i++) { consider.PB(known[i-1]); consider.PB(known[N-i]); } sort(all(consider)); consider.erase(unique(consider.begin(), consider.end()), consider.end()); for(int i = 1; i+K-1 <= consider.size(); i++) { ll sum = 0; for(int j = 0; j < K; j++) sum += consider[i-1+j].F; if(A <= sum && sum <= 2*A) { vector<int> ans; for(int j = 0; j < K; j++) ans.PB(consider[i-1+j].S); answer(ans); } } impossible(); } else { // S < N // S >= 40 for every test (or equal to N) // Therefore, N > 40 (if not testing locally) int lo = 1, hi = N; // find first x such that x >= A while(lo < hi) { int m = (lo+hi)/2; if(skim(m) < A) { lo = m+1; } else { hi = m; } } for(int i = 1; i <= K; i++) { known.PB({skim(i), i}); } ll sum = skim(lo); ll mx = sum; for(int i = 1; i < K; i++) sum += known[i-1].F; if(A <= sum && sum <= 2*A) { vector<int> ans; for(int i = 1; i < K; i++) ans.PB(known[i-1].S); ans.PB(lo); answer(ans); } vector<pair<ll, int>> consider = known; for(int i = 1; i <= K; i++) { int where = lo-i+(mx < A); consider.PB({skim(where), where}); } sort(all(consider)); consider.erase(unique(consider.begin(), consider.end()), consider.end()); for(int i = 1; i+K-1 <= consider.size(); i++) { sum = 0; for(int j = 0; j < K; j++) sum += consider[i-1+j].F; if(A <= sum && sum <= 2*A) { vector<int> ans; for(int j = 0; j < K; j++) ans.PB(consider[i-1+j].S); answer(ans); } } impossible(); } } /* 6 3 10 6 1 2 3 4 5 6 6 3 16 6 1 2 3 4 5 6 15 3 42 20 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 */

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:36:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 1; i+K-1 <= consider.size(); i++) {
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~
books.cpp:81:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int i = 1; i+K-1 <= consider.size(); i++) {
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~
#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...