Submission #850703

#TimeUsernameProblemLanguageResultExecution timeMemory
850703d4xnA Difficult(y) Choice (BOI21_books)C++17
0 / 100
1 ms1112 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 ll long long const ll N = 1e5+5; ll dp[N]; /* ll pw(ll x, ll y) { int sum = 0; for (int i = 0; i < y; i++) { sum += x+i; } return sum; } ll pw2(ll x, ll y) { int sum = 0; for (int i = 0; i < y; i++) { sum += x-i; } return sum; }*/ int sum(int x, int y) { int cnt = 0; for (int i = 0; i < y; i++) { if (dp[x+i] == -1) dp[x+i] = skim(x+i); cnt += dp[x+i]; } return cnt; } void solve(int N, int K, long long A, int S) { // TODO implement this function /* if (skim(2) == 42) { impossible(); } else { answer({1, 3}); } */ memset(dp, -1, sizeof(dp)); ll l = 1; ll r = N-K; while (l < r) { ll mid = (l+r)>>1; int x = sum(mid, K); if (x < A) l = mid+1; else if (x > A*2) r = mid-1; else { l = r = mid; break; } } int x = sum(l, K); if (x < A || A*2 < x) impossible(); vector<int> ans(K); for (int i = 0; i < K; i++) { ans[i] = l+i; } answer(ans); /* l = L; r = N; while (l < r) { ll mid = (l+r+1)>>1; dp[mid] = skim(mid); if (pw2(dp[mid], K) > A*2) r = mid-1; else l = mid; //cerr << mid << " " << dp[mid] << " " << K << " " << A << " " << l << " " << r << endl; } ll R = l; if (R-L+1 >= K) { vector<int> ans; int cnt = 0; for (int i = L; i <= R; i++) { ans.push_back(i); cnt++; if (cnt == K) break; } answer(ans); } else impossible(); */ /* ll x = l; for (ll i = 1; i < K; i++) { if (x+i <= N) dp[x+i] = skim(x+i); if (x-i > 0) dp[x-i] = skim(x-i); } vector<ll> v; for (int i = x-K+1; i <= x+K-1; i++) { if (0 < i && i <= N) v.push_back(i); } ll sz = v.size(); for (ll mask = 0; mask < (1ll << sz); mask++) { if (__builtin_popcount(mask) != K) continue; vector<int> ans; ll sum = 0; for (int i = 0; i < sz; i++) { if ((mask >> i) & 1ll) { ans.push_back(v[i]); sum += dp[v[i]]; } } if (A <= sum && sum <= A*2) { answer(ans); return; } } impossible(); */ } /* #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 ll long long int n, k, s; ll a; vector<ll> v, pre; vector<int> ans; bool ended; void generate(int idx, int prev, ll sum) { if (ended) return; if (sum > a*2) return; if (n-prev < k-idx) return; if (sum + pre[n] - pre[n-(k-idx)] < a) return; if (idx == k) { if (a <= sum && sum <= a*2) { ended = 1; return; } return; } for (int i = prev+1; i <= n; i++) { ans[idx] = i; generate(idx+1, i, sum + v[i]); if (ended) return; } } void solve(int N, int K, long long A, int S) { // TODO implement this function // impossible() // answer() // puedo hacer S preguntas // hay N libros // ordenados de mayor a menor por precio // tengo que comprar K // y la suma tiene que ser >= A y <= A*2 n = N; k = K; a = A; s = S; v.resize(n+1); pre.resize(n+1, 0); for (int i = 1; i <= n; i++) { v[i] = skim(i); pre[i] = pre[i-1] + v[i]; } ended = 0; ans.resize(k); generate(0, 0, 0ll); if (!ended) impossible(); answer(ans); } */
#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...