제출 #436547

#제출 시각아이디문제언어결과실행 시간메모리
4365472qbingxuanDetecting Molecules (IOI16_molecules)C++14
69 / 100
1037 ms5724 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; for (int i = 0; i <= n; i++) { for (int j = n+1; j > i; j--) { if (l <= pre[i] + suf[j] && pre[i] + suf[j] <= u) { 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 {}; }

컴파일 시 표준 에러 (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...