Submission #72584

#TimeUsernameProblemLanguageResultExecution timeMemory
72584aleksamDetecting Molecules (IOI16_molecules)C++14
100 / 100
146 ms41312 KiB
#pragma once #include <bits/stdc++.h> #define MAX_N 500000 using namespace std; long long L[MAX_N], D[MAX_N]; int N; struct p{ int id, val; }w[MAX_N]; bool operator<(const p a, const p b){ return a.val<b.val; } set<long long> S; vector<int> find_subset(int l, int u, vector<int> W) { N=W.size(); for(int i=0; i<N; ++i){ w[i].id=i; w[i].val=W[i]; } sort(w, w+N); L[0]=w[0].val; for(int i=0; i<N; ++i){ if(i) L[i]=L[i-1]+w[i].val; if(L[i]>=l && L[i]<=u){ vector<int> ret; for(int j=0; j<i+1; ++j){ ret.push_back(w[j].id); } return ret; } } D[N-1]=w[N-1].val; for(int i=N-1; i>=0; --i){ if(N-1-i) D[i]=D[i+1]+w[i].val; if(D[i]>=l && D[i]<=u){ vector<int> ret; for(int j=N-1; j>=i; --j){ ret.push_back(w[j].id); } return ret; } } for(int i=N-2; i>=0; --i){ S.insert(D[i+1]); auto x=S.lower_bound((long long)l-L[i]); if(x==S.end())continue; long long val=*x; if(val<=(long long)u-L[i]){ //To je to, nasao sam resenje vector<int> ret; int ind=-1; for(int j=i+1; j<N; ++j) if(D[j]==val) ind=j; int sum=0; for(int j=0; j<=i; ++j){ ret.push_back(w[j].id); sum+=w[j].val; } assert(sum==L[i]); for(int j=ind; j<N; ++j){ ret.push_back(w[j].id); sum+=w[j].val; } assert(sum==L[i]+D[ind]); //assert(sum<=u && sum>=l); return ret; } } vector<int> ret; return ret; }

Compilation message (stderr)

molecules.cpp:1:9: warning: #pragma once in main file
 #pragma once
         ^~~~
#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...