제출 #966898

#제출 시각아이디문제언어결과실행 시간메모리
966898Hugo1729Detecting Molecules (IOI16_molecules)C++11
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; typedef long long ll; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<pair<int,int>> sus; for(int i=0;i<n;i++)sus.push_back({w[i],i}); sort(w.begin(),w.end()); sort(sus.begin(),sus.end()); ll pref[n+1]; pref[0]=0; for(int i=0;i<n;i++)pref[i+1]=pref[i]+w[i]; // for(int i=0;i<n+1;i++)cout << pref[i] << " "; // cout << '\n'; int a=0,b=n; if(pref[n]<u)a=n; else if(pref[1]>u)return vector<int>(0); else{ while(a<b-1){ int mid = (a+b)/2; // cout << a << ' ' << b << ' ' << mid << '\n'; if(pref[mid]<u)a=mid; else b=mid; } } if(a==0||pref[n]<l||pref[a]>u||pref[n]-pref[n-a]<l) return vector<int>(0); int c=0,d=a; while(c<d-1){ int mid=(d+c)/2; // cout << c << ' ' << d << ' ' << mid << ' ' << pref[a-mid]+pref[n]-pref[n-mid] << '\n'; if(pref[a-mid]+pref[n]-pref[n-mid]<u)c=mid; else d = mid; } if(pref[a-c]+pref[n]-pref[n-c]<u)c++; // cout << a << ' ' << c << '\n'; vector<int> ans; for(int i=0;i<a-c;i++)ans.push_back(sus[i].second); for(int i=n-1;i>=n-c;i--)ans.push_back(sus[i].second); 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...