이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 1000001;
const ll VMAX = 1001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll base = 31;
const ll nr_of_bits = 21;
map <int, ll> mp;
ll afla(int i) {
if(mp.find(i) != mp.end())
return mp[i];
return mp[i] = skim(i);
}
void solve(int N, int K, long long A, int S) {
ll sum = 0, i;
vector <int> first;
for(int i = 1; i <= K; i++) {
ll acum = afla(i);
first.push_back(i);
sum += acum;
}
if(sum > 2 * A) {
impossible();
return;
}
if(sum >= A && sum <= 2 * A) {
answer(first);
return;
}
int r = 0, pas = (1 << nr_of_bits);
while(pas) {
if(r + pas <= N) {
ll acum = afla(r + pas);
if(acum <= A) {
r += pas;
}
}
pas /= 2;
}
vector <int> second;
int ini = r;
vector <int> trei = first, patru = second;
if(r < N)
r++;
if(r < K) {
impossible();
return;
}
sum = 0;
for(i = r; i >= r - K + 1; i--) {
second.push_back(i);
sum += afla(i);
}
if(sum >= A && sum <= 2 * A) {
answer(second);
return;
}
for(i = 1; i < K; i++) {
sum += afla(first[i - 1]);
sum -= afla(second[i]);
swap(second[i], first[i - 1]);
if(sum >= A && sum <= 2 * A) {
answer(second);
return;
}
}
r = ini;
first = trei;
second = patru;
if(r < K) {
impossible();
return;
}
sum = 0;
for(i = r; i >= r - K + 1; i--) {
second.push_back(i);
sum += afla(i);
}
if(sum >= A && sum <= 2 * A) {
answer(second);
return;
}
for(i = 1; i < K; i++) {
sum += afla(first[i - 1]);
sum -= afla(second[i]);
swap(second[i], first[i - 1]);
if(sum >= A && sum <= 2 * A) {
answer(second);
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... |