이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
ll a[maxn];
// --- 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(int N, int k, ll A, int S) {
int l = 1, r = N;
while(l < r) {
int mid = (l + r) >> 1;
a[mid] = skim(mid);
if(a[mid] >= A) r = mid;
else l = mid + 1;
}
int pos_A = l;
if(pos_A < k) {
impossible();
return;
}
if(pos_A == k) {
ll ans = a[pos_A];
for(int i = 1; i < k; i++) a[i] = skim(i);
for(int i = 1; i < k; i++) ans += a[i];
if(ans >= A && ans <= A * 2) {
vector<int> vc;
for(int i = 1; i <= k; i++) vc.push_back(i);
answer(vc);
return;
}
impossible();
return;
}
ll ans = 0;
for(int i = 1; i <= k; i++) a[i] = skim(i), ans += a[i];
if(ans >= A && ans <= A * 2) {
vector<int> vc;
for(int i = 1; i <= k; i++) vc.push_back(i);
answer(vc);
return;
}
if(ans > A * 2) {
impossible();
return;
}
ans -= a[k], ans += a[pos_A];
if(ans >= A && ans <= A * 2) {
vector<int> vc;
for(int i = 1; i < k; i++) vc.push_back(i);
vc.push_back(pos_A);
answer(vc);
return;
}
ans -= a[pos_A], ans += a[k];
vector<int> vc, vc2;
for(int i = k; i > 0; i--) vc.push_back(i);
for(int i = pos_A - 1; i > k; i--) {
int ind = pos_A - i;
a[i] = skim(i);
ans -= a[ind], ans += a[i];
vc.pop_back();
vc2.push_back(i);
if(ans >= A && ans <= A * 2) {
vector<int> ans_t;
for(auto j : vc) ans_t.push_back(j);
for(auto j : vc2) ans_t.push_back(j);
answer(ans_t);
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... |