Submission #941640

#TimeUsernameProblemLanguageResultExecution timeMemory
941640shoryu386A Difficult(y) Choice (BOI21_books)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; typedef long long ll; long long gA, gK; void recur(int x, int taken, ll sum, vector<pair<int, ll>> takeitem, vector<pair<int, ll>> &items){ if (taken == gK){ if (gA <= sum && sum <= 2LL*gA){ vector<int> indices; for (int x = 0; x < (int)takeitem.size(); x++){ indices.push_back(t[x].first); } answer(indices); return; } return; } #include <bits/stdc++.h> #include "books.h" using namespace std; typedef long long ll; long long gA, gK; void recur(int x, int taken, ll sum, vector<pair<int, ll>> takeitem, vector<pair<int, ll>> &items){ if (taken == gK){ if (gA <= sum && sum <= 2LL*gA){ vector<int> indices; for (int x = 0; x < (int)takeitem.size(); x++){ indices.push_back(t[x].first); } answer(indices); return; } return; } if (x == items.size()) return; recur(x+1, taken, sum, takeitem, items); if (taken != gK){ takeitem.push_back(items[x]); recur(x+1, taken+1, sum+items[x].second, takeitem, items); } } void solve(int N, int K, long long A, int S) { // TODO implement this function //k books, sum of A //x, x+1, x+2, x+3, x+4, x+5... and so on gA = A; gK = K; int extrasum = 0; for (int x = 0; x < K; x++){ extrasum += x; } //we want A <= x*K + extrasum <= 2*A //x*K + extrasum >= A //x*K >= A-extrasum //x >= (A-extrasum)/K ll target = (A - extrasum)/K + ((A - extrasum)%K != 0); //to do: check rounding if (A - extrasum <= 0) {impossible(); return;} int l = 1, r = N+1-K, ans = N+1-K; while (l <= r){ int m = (l+r)/2; ll res = skim(m); if (res >= target){ r = m-1; ans = m; } else{ l = m+1; } } vector<pair<int, ll>> items; set<int> indicesInside; for (int x = max(1, ans-10); x < min(N+1, ans+K); x++){ items.push_back({x, skim(x)}); indicesInside.insert(x); } for (int x = 1; x <= 10; x++){ if (indicesInside.count(x) == 0) items.push_back({x, skim(x)}), indicesInside.insert(x); } recur(0, 0, 0, {}, items); impossible(); }

Compilation message (stderr)

books.cpp: In function 'void recur(int, int, ll, std::vector<std::pair<int, long long int> >, std::vector<std::pair<int, long long int> >&)':
books.cpp:16:23: error: 't' was not declared in this scope
   16 |     indices.push_back(t[x].first);
      |                       ^
books.cpp:32:99: error: a function-definition is not allowed here before '{' token
   32 | void recur(int x, int taken, ll sum, vector<pair<int, ll>> takeitem, vector<pair<int, ll>> &items){
      |                                                                                                   ^
books.cpp:54:46: error: a function-definition is not allowed here before '{' token
   54 | void solve(int N, int K, long long A, int S) {
      |                                              ^
books.cpp:31:11: warning: unused variable 'gA' [-Wunused-variable]
   31 | long long gA, gK;
      |           ^~
books.cpp:31:15: warning: unused variable 'gK' [-Wunused-variable]
   31 | long long gA, gK;
      |               ^~
books.cpp:105:1: error: expected '}' at end of input
  105 | }
      | ^
books.cpp:11:99: note: to match this '{'
   11 | void recur(int x, int taken, ll sum, vector<pair<int, ll>> takeitem, vector<pair<int, ll>> &items){
      |                                                                                                   ^