This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
void solve(int N, int K, long long A, int S) {
// TODO implement this function
/*
if (skim(2) == 42) {
impossible();
} else {
answer({1, 3});
}
*/
ll l = 1;
ll r = N;
while (l < r) {
ll mid = (l+r)>>1;
dp[mid] = skim(mid);
if (pw(dp[mid], K) >= A) r = mid;
else l = mid+1;
//cerr << mid << " " << dp[mid] << " " << K << " " << A << " " << l << " " << r << endl;
}
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();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |