제출 #424541

#제출 시각아이디문제언어결과실행 시간메모리
424541benedict0724Detecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms204 KiB
#include "molecules.h" #include <algorithm> using namespace std; typedef long long ll; vector<int> find_subset(int l, int u, std::vector<int> w) { ll s = 1e15; int n = (int)w.size(); for(int i=0;i<n;i++) s = min(s, (ll)w[i]); vector<ll> pre, suf; vector<pair<ll, ll>> v; for(int i=0;i<n;i++) pre.push_back(w[i] - s); for(int i=0;i<n;i++) suf.push_back(w[i] - s); for(int i=0;i<n;i++) v.push_back({w[i], i}); sort(pre.begin(), pre.end()); sort(suf.rbegin(), suf.rend()); for(int i=1;i<n;i++) pre[i] += pre[i-1]; for(int i=1;i<n;i++) suf[i] += suf[i-1]; sort(v.begin(), v.end()); vector<int> ans; for(int i=1;i<=n;i++) { ll m_in = s * i + pre[i-1], m_ax = s * i + suf[i-1]; if(m_ax < l || u < m_in) continue; ll now = m_in; for(int j=0;j<i;j++) { if(l <= now && now <= u) { for(int k=0;k<j;k++) { ans.push_back(v[n-1-k].second); } for(int k=0;k<i-j;k++) { ans.push_back(v[k].second); } return ans; } now -= pre[i-1-j]; if(j < i-1) now += pre[i-2-j]; if(j > 0) now -= suf[j-1]; now += suf[j]; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...