답안 #54138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54138 2018-07-02T13:02:03 Z WLZ Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
#include "molecules.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

vector<int> find_subset(int l, int u, vector<int> w) {
  n = (int) w.size();
  vector< pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    v.emplace_back(w[i], i);
  }
  sort(v.begin(), v.end());
  int i = 0, j = 0;
  long long cur = 0ll;
  vector<int> was(n, 0);
  int cnt = 0;
  for (;;) {
    while (i < n && cur < (long long) l) {
      was[v[i].second] = 1;
      cur += (long long) v[i++].first;      
      cnt++;
    }
    while (j < n && cur > (long long) u) {
      was[v[j].second] = 0;
      cur -= (long long) v[j++].first;
      cnt--;
    }
    if (cur >= l && cur <= u) {
      vector<int> ans;
      for (int i = 0; i < n; i++) {
        if (was[i]) {
          ans.push_back(i);
        }
      }
      return ans;
    }
    if (i >= n || j >= n) {
      break;
    }
  }
  return {};
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:10:3: error: 'n' was not declared in this scope
   n = (int) w.size();
   ^