This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Sylwia Sapkowska
#include <bits/stdc++.h>
#include "books.h"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
//
// --- 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.
//
void solve(int32_t N, int32_t K, long long A, int32_t S) {
int n = N;
int k = K;
int L = 1, R = n, ans = n;
while (R >= L){
int mid = (L+R)/2;
if (skim(mid) >= A){
ans = mid;
R = mid-1;
} else {
L = mid+1;
}
}
vector<T>curr;
for (int i = 1; i<=min(k, ans); i++) curr.emplace_back(skim(i), i);
for (int i = ans, ck = k; i>=1 && ck > 0; i--, ck--){
curr.emplace_back(skim(i), i);
}
sort(curr.begin(), curr.end());
curr.erase(unique(curr.begin(), curr.end()), curr.end());
debug(curr);
int M = (int)curr.size();
for (int mask = 1; mask<(1<<M); mask++){
if (__builtin_popcountll(mask) != k) continue;
int sum = 0;
for (int i = 0; i<M; i++){
if (mask&(1<<i)){
sum += curr[i].first;
}
}
if (sum >= A && sum <= 2*A) {
vector<int32_t>ans;
for (int i = 0; i<n; i++){
if (mask&(1<<i)){
ans.emplace_back(curr[i].second);
}
}
answer(ans);
exit(0);
}
}
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... |