이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
//
// --- 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.
//
map<int,lld> m;
lld query(int pos){
if(m.find(pos)==m.end()){
lld x=skim(pos+1);
m[pos]=x;
return x;
}
return m[pos];
}
void solve(int N, int K, long long A, int S) {
int lo=-1;
int hi=N;
while(hi-lo>1){
int mid=(hi+lo)/2;
if(query(mid)<=2*A){
lo=mid;
}else hi=mid;
}
if(lo<K)impossible();
vector<pair<lld,int> > books;
int k=K;
rep(i,0,k){
books.push_back({query(i),i});
}
for(int i=lo;i>lo-k && i>=0;i--){
books.push_back({query(i),i});
}
sort(books.begin(),books.end());
books.resize(unique(books.begin(),books.end())-books.begin());
vector<int> St;
rep(msk,0,(1<<books.size())){
lld sum=0;
St.clear();
rep(i,0,(int)books.size()){
if((msk&(1<<i))>0){
St.push_back(books[i].second+1);
sum+=books[i].first;
}
}
if(sum>=A && sum<=2*A && (int)St.size()==k){
answer(St);
}
}
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... |