이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "books.h"
typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 100010
#define INF (ll)1e18
#define MOD 998244353
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
//~ //
// --- 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.
//
ll memo[maxn];
ll qry(int x){
if (memo[x] != -1) return memo[x];
return memo[x] = skim(x);
}
void solve(int N, int K, long long A, int S) {
mem(memo, -1);
int l = 0, r = N + 1;
while (l + 1 < r){
int m = (l + r) / 2;
if (qry(m) > A) r = m;
else l = m;
}
int x = r;
ll sm1 = 0, sm2 = 0;
FOR(i,1,K) sm1 = min(INF, sm1 + qry(i));
if (x <= K){
if (A <= sm1 && sm1 <= 2 * A){
vi ans;
FOR(i,1,K) ans.pb(i);
answer(ans);
}else impossible();
return;
}
FOR(i,x-K,x-1) sm2 = min(INF, sm2 + qry(i));
ll sm3 = 0;
FOR(i,1,K-1) sm3 = min(INF, sm3 + qry(i));
// if there is an element > A
if (x <= N && A <= qry(x) + sm3 && qry(x) + sm3 <= 2 * A){
vi ans;
FOR(i,1,K-1) ans.pb(i);
ans.pb(x);
answer(ans); return;
}
if (sm1 > 2 * A || sm2 < A){
impossible(); return;
}
if (sm1 >= A){
vi ans;
FOR(i,1,K) ans.pb(i);
answer(ans); return;
}
if (sm2 <= 2 * A){
vi ans;
FOR(i,x-K,x-1) ans.pb(i);
answer(ans); return;
}
vector <ll> v, idx;
// can create from elements in [1,K] and [x-K,x-1]
FOR(i,1,N) if (i <= K || (i >= x - K && i <= x - 1)){
if (!v.empty()) assert(v.back() < qry(i));
v.pb(qry(i)); idx.pb(i);
}
FOR(i,0,(int)v.size()-1) if (i + K - 1 < (int)v.size()){
ll sm = 0;
FOR(j,i,i+K-1) sm = min(INF, sm + v[j]);
if (A <= sm && sm <= 2 * A){
vi ans;
FOR(j,i,i+K-1) ans.pb(idx[j]);
answer(ans); return;
}
//~ if (i == 0) assert(sm < A);
//~ if (i + K == (int)v.size()) assert(sm > 2 * A);
}
//~ assert(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... |