Submission #744352

#TimeUsernameProblemLanguageResultExecution timeMemory
744352Dan4LifeDetecting Molecules (IOI16_molecules)C++17
0 / 100
52 ms65536 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() using ll = long long; const int mxN = (int)2e5+10; ll pre[mxN]; /* 4 15 17 6 8 8 7 */ vector<int> find_subset(int L, int R, vector<int> w) { vector<pair<int,int>> v; v.clear(); for(int i = 1; auto u : w) v.pb({u,i++}); sort(all(v)); int n = sz(v); pre[0]=0; for(int i = 0; i < n; i++) pre[i+1] = pre[i]+(ll)v[i].first; vector<int> ans; ans.clear(); for(int i = 0; i < n; i++){ int l = i+1, r = n; if(pre[r]-pre[i]<L) continue; L+=pre[i], R+=pre[i]; while(l<r){ int mid = (l+r)/2; if(pre[mid]<L) l=mid+1; else r=mid; } if(L<=pre[l] and pre[l]<=R){ for(int j = i; j < l; i++) ans.pb(v[j].second); return ans; } L-=pre[i], R-=pre[i]; } return ans; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:16:20: warning: range-based 'for' loops with initializer only available with '-std=c++2a' or '-std=gnu++2a'
   16 |     for(int i = 1; auto u : w) v.pb({u,i++});
      |                    ^~~~
#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...