Submission #393829

#TimeUsernameProblemLanguageResultExecution timeMemory
393829teehandsomeDetecting Molecules (IOI16_molecules)C++11
100 / 100
62 ms5188 KiB
#include "molecules.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define endl '\n' #define INF 1e9+7 #define all(x) x.begin(),x.end() using namespace std; using namespace __gnu_pbds; using ll=long long; using pii=pair<int,int>; using ppi=pair<int,pii>; using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>; template<typename T> void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";} void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";} template<typename T> void _print(T x) {cerr<<x;} void dbg() {cerr<<endl;} template<typename Head,typename... Tail> void dbg(Head H,Tail... T) { _print(H); if(sizeof...(T)) cerr<<","; else cerr<<"\"]"; dbg(T...); } #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__) //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> f(int l,int r,vector<pii> ww) { vector<int> ans; for(int i=l;i<r;i++) { ans.push_back(ww[i].second); } sort(all(ans)); return ans; } std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n=w.size(); vector<pii> ww(n); ll sumall=0; for(int i=0;i<n;i++) { ww[i].first=w[i]; ww[i].second=i; sumall+=w[i]; } sort(all(ww)); // ll sumall=accumulate(all(w),0LL); if(sumall<l or ww[0].first>u) return vector<int>(0); int L=0,R=0; //[L,R) ll sum=0; while(R<n) { while(R<n) { sum+=ww[R++].first; if(sum>=l) break; } if(sum>=l and sum<=u) { return f(L,R,ww); } while(L+1<=R) { sum-=ww[L++].first; if(sum<=u) break; } if(sum>=l and sum<=u) { return f(L,R,ww); } } while(sum>u and L<n) sum-=ww[L++].first; if(sum>=l and sum<=u) return f(L,R,ww); return vector<int>(0); }
#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...