Submission #436550

#TimeUsernameProblemLanguageResultExecution timeMemory
4365502qbingxuanDetecting Molecules (IOI16_molecules)C++14
100 / 100
131 ms21172 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n = w.size(); // l / w_min vector<int> id(n); iota(id.begin(), id.end(), 0); if (long long sum = accumulate(w.begin(), w.end(), 0LL); l <= sum && sum <= u) { return id; } sort(id.begin(), id.end(), [&w](size_t a, size_t b) { return w[a] < w[b]; }); vector<int> W(n); for (int i = 0; i < n; i++) W[i] = w[id[i]]; vector<long long> pre(n+1), suf(n+2); for (int i = 1; i <= n; i++) pre[i] = pre[i-1] + W[i-1]; for (int i = n; i >= 1; i--) suf[i] = suf[i+1] + W[i-1]; long long sum = 0; map<long long,int> mp; for (int i = n; i >= 0; i--) { mp[suf[i+1]] = i+1; // minimum x s.t. x >= l - pre[i] auto it = mp.lower_bound(l - pre[i]); if (it != mp.end() && pre[i] + it->first <= u) { int j = it->second; vector<int> ans; for (int t = 0; t < i; t++) ans.push_back(id[t]); for (int t = j; t <= n; t++) ans.push_back(id[t-1]); return ans; } } return {}; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:9: warning: init-statement in selection statements only available with '-std=c++17' or '-std=gnu++17'
   11 |     if (long long sum = accumulate(w.begin(), w.end(), 0LL); l <= sum && sum <= u) {
      |         ^~~~
molecules.cpp:20:15: warning: unused variable 'sum' [-Wunused-variable]
   20 |     long long sum = 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...