#include <bits/stdc++.h>
#include "books.h"
using namespace std;
//#define ll long long
//
// --- 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,long long> mp;
long long query(int x){
if(mp.find(x)!=mp.end()) return mp[x];
else return mp[x]=skim(x);
}
void solve(int N, int K, long long A, int S) {
vector<int> ans(K);
int l=1,r=N,pos=N+1;
while(l<=r){
int mid=(l+r)>>1;
if(query(mid)>=A) pos=mid,r=mid-1;
else l=mid+1;
}
vector<pair<long long,int>> d;
for(int i=1;i<=min(K,pos-1);i++) d.push_back({query(i),i});
for(int i=pos-1;i>=max(min(K,pos-1)+1,pos-K);i--) d.push_back({query(i),i});
sort(d.begin(),d.end());
if((int)d.size()>=K-1){
long long total=0;
for(int i=0;i<K-1;i++) total+=d[i].first;
total+=query(pos);
if(total>=A && total<=2*A){
for(int i=0;i<K-1;i++) ans[i]=d[i].second;
ans[K-1]=pos;
answer(ans);
return;
}
}
int sz=(int)d.size();
for(int i=0;i<(1<<sz);i++){
if(__builtin_popcount(i)!=K) continue;
long long total=0;
for(int j=0;j<sz;j++) if(i>>j&1) total+=d[j].first;
if(A<=total && total<=2*A){
ans.clear();
for(int j=0;j<sz;j++) if(i>>j&1) ans.push_back(d[j].second);
answer(ans);
return;
}
}
impossible();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Runtime error |
0 ms |
440 KB |
Execution killed with signal 13 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Runtime error |
0 ms |
440 KB |
Execution killed with signal 13 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Runtime error |
13 ms |
440 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Runtime error |
13 ms |
440 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Runtime error |
13 ms |
440 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Runtime error |
13 ms |
440 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Runtime error |
13 ms |
440 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |