이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
#define ll long long
const ll N = 1e5+5;
ll dp[N];
ll sum(ll x, ll y) {
ll cnt = 0;
for (ll 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) {
memset(dp, -1, sizeof(dp));
ll l = 1;
ll r = N;
while (l < r) {
ll mid = (l+r)>>1;
if (dp[mid] == -1) dp[mid] = skim(mid);
if (dp[mid] < A) l = mid+1;
else r = mid;
}
vector<int> test = {l};
ll cnt = dp[l];
for (ll i = 0; i < K-1; i++) {
if (dp[i] == -1) dp[i] = skim(i);
cnt += dp[i];
}
if (A <= cnt && cnt <= A*2) answer(test);
l = 1;
r = N-K+1;
while (l < r) {
ll mid = (l+r)>>1;
ll x = sum(mid, K);
if (x < A) l = mid+1;
else if (x > A*2) r = mid-1;
else {
l = r = mid;
break;
}
}
ll x = sum(l, K);
if (x < A || A*2 < x) impossible();
vector<int> ans(K);
for (ll 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);
}
*/
컴파일 시 표준 에러 (stderr) 메시지
books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:34:25: warning: narrowing conversion of 'l' from 'long long int' to 'int' [-Wnarrowing]
34 | vector<int> test = {l};
| ^
books.cpp:34:25: warning: narrowing conversion of 'l' from 'long long int' to 'int' [-Wnarrowing]
# | 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... |