# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
62154 | ernestvw | Detecting Molecules (IOI16_molecules) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> solve(int l, int u, vector<int> w) {
vector<int> ans;
vector<pair<int, int>> W;
int n = (int)w.size();
for(int i = 0; i < n; i++) W.push_back({w[i], i});
sort(W.begin(), W.end());
vector<long long> prefix(n+1);
prefix[0] = 0;
for(int i = 1; i <= n; i++) prefix[i] = prefix[i-1] + (long long)W[i-1].first;
for(int i = 0; i < n; i++) {
long long remove = prefix[i];
if(prefix[n] - remove < l) continue;
int cur = i;
for(int jump = 20; jump >= 0; jump--)
if((1 << jump) + cur < n and prefix[(1 << jump) + cur + 1] - remove < l)
cur += (1 << jump);
cur++;
if(prefix[cur + 1] - remove > u) continue;
for(int j = i; j <= cur; j++) ans.push_back(W[j].second);
return ans;
}
return ans;
}