Submission #851607

#TimeUsernameProblemLanguageResultExecution timeMemory
851607pomuchleDetecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms600 KiB
#ifdef DEBUG #include <cstdio> #include <vector> #include <cassert> std::vector<int> find_subset(int l, int u, std::vector<int> w); int main() { int n, l, u; assert(3 == scanf("%d %d %d", &n, &l, &u)); std::vector<int> w(n); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &w[i])); std::vector<int> result = find_subset(l, u, w); printf("%d\n", (int)result.size()); for (int i = 0; i < (int)result.size(); i++) printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]); } #else #include "molecules.h" #endif #include <ios> #include <algorithm> #include <cassert> #include <vector> #include <queue> #define REP(i, n) for(int i=0; i<(n); ++i) #define FOR(i, p, n) for(int i=(p); i<=(n); ++i) #define sz(A) (int(A.size())) #define V std::vector typedef long long ll; typedef V <int> vi; typedef V <ll> vll; typedef V <bool> vb; vi find_subset(int p, int k, vi w) { int n=sz(w); V <std::pair <int, int>> v(n); REP(i, n) v[i]={w[i], i}; std::sort(v.begin(), v.end()); ll s1=0,s2=0; vi n1,n2,wv; REP(i, n){ s1+=v[i].first,s2+=v[n-1-i].first; n1.emplace_back(i); n2.emplace_back(n-1-i); if (s1>k) break; if (s2<p) continue; // s1<=k,s2>=p REP(j, i){ if (s1>=p) break; s1-=v[n1[j]].first; s2-=v[n2[j]].first; s1+=v[n2[j]].first; s2+=v[n1[j]].first; std::swap(n1[j], n2[j]); } //assert(s1>=p&&s1<=k); for (int j : n1) wv.emplace_back(v[j].second); break; } return wv; }
#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...