Submission #966897

#TimeUsernameProblemLanguageResultExecution timeMemory
966897Hugo1729Detecting Molecules (IOI16_molecules)C++11
0 / 100
1 ms600 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) { vector<pair<int,int>> sus; for(int i=0;i<w.size();i++)sus.push_back({w[i],i}); sort(w.begin(),w.end()); sort(sus.begin(),sus.end()); int n = w.size(); 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; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i=0;i<w.size();i++)sus.push_back({w[i],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...