Submission #721166

#TimeUsernameProblemLanguageResultExecution timeMemory
721166FatihSolakA Difficult(y) Choice (BOI21_books)C++17
30 / 100
1 ms336 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. // int cnt = 0; long long get(int pos){ assert(cnt++ <= 40); return skim(pos); } void solve(int n, int k, long long a, int s){ int l = 1,r = n+1; while(l < r){ int m = (l+r)/2; if(get(m) < a){ l = m + 1; } else r = m; } vector<pair<int,long long>> x; vector<pair<int,long long>> y; for(int i = 1;i<=k;i++){ x.push_back({i,get(i)}); } if(l < k){ impossible(); return; } if(l != n+1){ long long sum = get(l); for(int i = 0;i<k-1;i++){ sum += x[i].second; } if(a <= sum && sum <= 2*a){ vector<int> ret; for(int i = 1;i<=k-1;i++){ ret.push_back(i); } ret.push_back(l); assert(ret.size() == k); answer(ret); return; } } if(l == k){ impossible(); return; } for(int i = k;i>=1;i--){ y.push_back({l-i,get(l-i)}); } long long sum = 0; for(auto u:x){ sum += u.second; } if(a <= sum && sum <= 2*a){ vector<int> ret; for(int i = 1;i<=k;i++){ ret.push_back(i); } assert(ret.size() == k); answer(ret); return; } if(sum > 2*a){ impossible(); return; } for(int i = 1;i<=k;i++){ sum -= x[k-i].second; sum += y[k-i].second; if(a <= sum && sum <= 2*a){ vector<int> ret; for(int j = 1;j<=k-i;j++){ ret.push_back(i); } for(int j = k-1;j>=k-i;j--){ ret.push_back(y[j].first); } assert(ret.size() == k); answer(ret); sort(ret.begin(),ret.end()); return; } assert(sum < a); } impossible(); }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from books.cpp:1:
books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:49:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |             assert(ret.size()  == k);
      |                    ~~~~~~~~~~~~^~~~
books.cpp:70:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |         assert(ret.size()  == k);
      |                ~~~~~~~~~~~~^~~~
books.cpp:89:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   89 |             assert(ret.size()  == k);
      |                    ~~~~~~~~~~~~^~~~
#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...