Submission #1070052

#TimeUsernameProblemLanguageResultExecution timeMemory
1070052TheQuantiXDetecting Molecules (IOI16_molecules)C++17
69 / 100
33 ms4048 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") using namespace std; using ll = int; ll n, m, q, k, x, y, a, b, c; vector<int> gen(ll x, vector< pair<ll, ll> > &v, ll l, ll u) { vector<int> st; vector<int> ans; ll num = 0; ll e = n - 1; for (int i = x - 1; i >= 0; i--) { st.push_back(i); num += v[i].first; } while (num < l) { ll x = st[st.size() - 1]; if (num - v[x].first + v[e].first <= u) { num -= v[x].first; num += v[e].first; ans.push_back(v[e].second); st.pop_back(); e--; } else { num -= v[x].first; num += v[x + 1].first; st[st.size() - 1]++; } } for (auto i : st) { ans.push_back(v[i].second); } return ans; } vector<int> find_subset(int l, int u, vector<int> w) { n = w.size(); vector<int> ans; vector< pair<ll, ll> > v; ll sum = 0; for (int i = 0; i < n; i++) { if (w[i] >= l && w[i] <= u) { ans.push_back(i); return ans; } v.push_back({w[i], i}); sum += w[i]; } sort(v.begin(), v.end()); ll mn = 0, mx = 0; for (int i = 0; i < n; i++) { mn += v[i].first; mx += v[n - 1 - i].first; // cout << mn << ' ' << mx << '\n'; if (min(mx, (ll)u) >= max(mn, (ll)l)) { return gen(i + 1, v, l, u); } } 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...