Submission #585979

#TimeUsernameProblemLanguageResultExecution timeMemory
585979Valters07Detecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms340 KiB
#include <bits/stdc++.h> #include "molecules.h" #pragma GCC optimize("O2,unroll-loops") #define fio ios_base::sync_with_stdio(0);cin.tie(0); #define ll long long #define en cin.close();return 0; #define pb push_back #define fi first//printf("%lli\n",cur); #define se second//scanf("%lli",&n); #define r0 return 0; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> find_subset(int l, int u, vector<int> inp) { int n = inp.size(); ll pf[n+1], sf[n+2]; vector<pair<int,int> > w(n+1); for(int i = 1;i<=n;i++) w[i]={inp[i-1],i-1}; sort(w.begin(),w.end()); pf[0]=sf[n+1]=0; for(int i = 1;i<=n;i++) pf[i]=pf[i-1]+w[i].fi, sf[n-i+1]=sf[n-i+2]+w[n-i+1].fi; if(pf[n]<l||u<pf[1]) return {}; for(int i = 1;i<=n;i++) { if(l<=pf[i]&&pf[i]<=u) { vector<int> ret; for(int j = 1;j<=i;j++) ret.pb(w[j].se); return ret; } } int k = 1; while(k<n&&pf[k+1]<l) k++; if(sf[n-k+1]<l) return {}; vector<int> ans(k); for(int i = 1;i<=k;i++) ans[i]=w[i].se; ll cur = pf[k]; for(int i = 1;cur<l;i++) cur-=w[i].fi, cur+=w[n-i+1].fi, ans[i-1]=w[n-i+1].se; sort(ans.begin(),ans.end());//style points 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...