Submission #242465

#TimeUsernameProblemLanguageResultExecution timeMemory
242465WhaleVomitDetecting Molecules (IOI16_molecules)C++14
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; #define f first #define s second #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define MOO(i, a, b) for(int i=a; i<b; i++) #define M00(i, a) for(int i=0; i<a; i++) #define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--) #define M00d(i,a) for(int i = (a)-1; i>=0; i--) #define FAST ios::sync_with_stdio(0); cin.tie(0); #define finish(x) return cout << x << '\n', 0; #define dbg(x) cerr << ">>> " << #x << " = " << x << "\n"; #define _ << " _ " << typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int,int> pi; typedef pair<ld,ld> pd; typedef complex<ld> cd; vi find_subset(int l, int u, vi w) { vi ws; for(int x: w) ws.pb(x); sort(all(ws)); ll least = 0; ll most = 0; vi res; for(int cnt = 1; cnt <= sz(ws); cnt++) { least += ws[cnt-1]; most += ws[sz(ws)-cnt]; if(l <= least && least <= u) { for(int j = 0; j < cnt; j++) { res.pb(ws[j]); } break; } else if(l <= most && most <= u) { for(int j = sz(ws)-cnt; j < sz(ws); j++) { res.pb(ws[j]); } break; } else if(least < l && u < most) { ll tot = least; int idx = 0; while(tot < l) { tot -= ws[cnt-1-idx]; tot += ws[sz(ws)-1-idx]; idx++; } for(int j = 0; j < cnt-idx; j++) { res.pb(ws[j]); } for(int j = sz(ws)-1; j >= sz(ws)-idx; j--) { res.pb(ws[j]); } break; } } if(sz(res) == 0) return res; int cnt = 0; for(int x: res) cnt += x; assert(l <= cnt && cnt <= u); multiset<int> inAns; for(int x: res) inAns.insert(x); vi ans; M00(i, sz(w)) { if(inAns.count(w[i])) { ans.pb(i+1); inAns.erase(inAns.find(w[i])); } } return ans; } /*int main() { FAST int l, u; cin >> l >> u; int n; cin >> n; vi v; M00(i, n) { int x; cin >> x; v.pb(x); } vi ans = find_subset(l,u,v); for(int i: ans) cout << i << " "; cout << "\n"; }*/
#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...