# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1198349 | grafff | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include "molecules.h"
#include <algorithm>
using namespace std;
vector <int> solve(int l, int u, vector <int> w){
int n = w.size(), res = 0;
map <int, int> mp;
set <int> st = {0};
mp[0] = -1;
bool flag = false;
for(int i = 0; i < n; i++){
for(int j : st){
int x = j + w[i];
if(mp[x] == 0 && w[0] != x){
mp[x] = i;
}
if(l <= x && x <= u){
flag = true;
res = x;
break;
}
}
if(flag){
break;
}
st = {};
for(auto &[x, y] : mp){
st.insert(x);
}
}
vector <int> ans;
int x = mp[res];
while(x >= 0){
ans.push_back(x);
res -= w[x];
x = mp[res];
}
return ans;
}