제출 #987277

#제출 시각아이디문제언어결과실행 시간메모리
987277normankr07Detecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #include "molecules.h" std::vector<int> find_subset(int l, int u, std::vector<int> w) { // for (int i = 1; i <= n; i++) // { // if (l <= w[i - 1] && w[i - 1] <= u) // { // return vector<int>(i); // } // } vector<pair<int, int>> ww; ll sum = 0; for (int i = 0; i < n; i++) { sum += w[i]; ww.push_back(make_pair(w[i], i)); } sort(ww.begin(), ww.end()); vector<int> id; for (int i = n - 1, j = n; i < j && i >= -1;) { while (sum > u && i >= 0) { sum -= ww[i].first; i--; } if (l <= sum && sum <= u) { for (int p = 0; p <= i; p++) id.push_back(ww[p].second); for (int p = j; p < n; p++) id.push_back(ww[p].second); return id; } j--; sum += ww[j].first; } return vector<int>(); }

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:17:25: error: 'n' was not declared in this scope
   17 |     for (int i = 0; i < n; i++)
      |                         ^
molecules.cpp:24:18: error: 'n' was not declared in this scope
   24 |     for (int i = n - 1, j = n; i < j && i >= -1;)
      |                  ^
molecules.cpp:24:36: error: 'j' was not declared in this scope
   24 |     for (int i = n - 1, j = n; i < j && i >= -1;)
      |                                    ^