# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
284309 | user202729 | Detecting Molecules (IOI16_molecules) | C++17 | 62 ms | 7160 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// moreflags=grader.cpp
// 16
// ... isn't the site revealing too much...
// (... what's with this bug?)
#include "molecules.h"
#include<vector>
#include<algorithm>
#include<numeric>
#if not LOCAL
#define NDEBUG 1
#endif
#include<cassert>
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
struct Item{int index, value;};
std::vector<Item> items(w.size());
for(int index=0; index<(int)w.size(); ++index)
items[index]={index, w[index]};
std::sort(begin(items), end(items),[&](Item first, Item sec){return first.value<sec.value;});
int count;
{
std::vector<int64_t> tmp; tmp.reserve(items.size());
for(auto& it: items) tmp.push_back(it.value);
std::partial_sum(begin(tmp), end(tmp), tmp.begin());
count=0; // maximum such that minimum sum <= u
for(int step=1<<30; step>>=1;)
if(count+step<=(int)tmp.size() and tmp[count+step-1]<=u)
count+=step;
auto const maxSum=tmp.back()-(count==(int)tmp.size()? 0: tmp.end()[-1-count]);
if(maxSum<l)
return {};
}
// so maximum sum >=l and minimum sum <=u
std::vector<char> mark(w.size());
int countLeft=count, countRight=0;
int64_t total=0;
for(int i=0; i<count; ++i){
mark[i]=true;
total+=items[i].value;
}
assert(total<=u);
while(total<l){
--countLeft; ++countRight;
assert(mark[countLeft]); assert(not mark[w.size()-countRight]);
int64_t const total1=total-items[countLeft].value+items[w.size()-countRight].value;
if(total1>u){
int i=countLeft;
while(total<l){
assert(mark[i]); assert(not mark[i+1]);
mark[i]=false; mark[i+1]=true;
total+=items[i+1].value-items[i].value;
++i;
}
assert(total<=u);
break;
}else{
total=total1;
mark[countLeft]=false; mark[w.size()-countRight]=true;
}
}
int64_t total_{};
std::vector<int> result; result.reserve(count);
for(int index=0; index<w.size(); ++index)
if(mark[index]){
result.push_back(items[index].index);
total_+=items[index].value;
}
assert(total==total_);
assert(l<=total); assert(total<=u);
return result;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |