제출 #568380

#제출 시각아이디문제언어결과실행 시간메모리
568380Trisanu_DasDetecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; #define ff first #define ss second vector<int> find_subset(int l, int u, vector<int> w){ vector<pair<int, int> > w_sort; int n = w.size(); for(int i = 0; i < n; i++) w_sort.push_back({w[i], i}); sort(w_sort.begin(), w_sort.end()); int sum = 0; vector<int> ans; for(int i = 0; i < n; i++){ sum += w_sort[i].ff; ans.push_back(w_sort[i].ss); if(l <= sum && sum <= u) return ans; } ans.clear(); if(sum > l || w_sort[0].ff > r) return ans; int last = 0; sum = 0; for(int i = 0; i < n; i++) { if(sum + w_sort[i].ff > l) break; sum += w_sort[i].ff; last = i; } int len = last + 1; for(int i = last + 1; i < n; i++) { sum -= w_sort[i - len].ff; sum += w_sort[i].ff; if(sum >= l) { for(int j = i - len + 1; j <= i; j++) ans.push_back(w_sort[j].ss); return ans; } } return ans; }

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:20:32: error: 'r' was not declared in this scope
   20 |   if(sum > l || w_sort[0].ff > r) return ans;
      |                                ^