답안 #1078403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078403 2024-08-27T16:42:56 Z sqrteipi Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<signed> find_subset(signed l, signed u, vector<signed> w) {
  int n = w.size(), r = u;
  vector<pair<int, int>> vec;
  for (int i=0; i<n; i++) {
    int k = w[i];
    vec.push_back({k, i});
  }
  sort(vec.begin(), vec.end());
  int mi = 0, ma = 0, li = 0, ri = n - 1;
  while (li < n) {
    mi += vec[li].first, ma += vec[ri].first;
    if (l <= mi && mi <= r) {
      vector<int> ans;
      ans.push_back(li+1);
      for (int i=0; i<=li; i++) ans.push_back(vec[i].second);
      return ans;
    }
    if (l <= ma && ma <= r) {
      vector<int> ans;
      ans.push_back(li+1);
      for (int i=ri; i<n; i++) ans.push_back(vec[i].second);
      return ans;
    }
    if (mi <= l && r <= ma) {
      int sum = mi - vec[li].first;
      for (int i=li; i<n; i++) {
        sum += vec[i].first;
        if (l <= sum && sum <= r) {
          vector<int> ans;
          ans.push_back(li+1);
          for (int j=i-li; j<=i; j++) ans.push_back(vec[i].second);
          return ans;
        }
        sum -= vec[i-li].first;
      }
    }
    li++, ri--;
  }
  return {};
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:20:14: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   20 |       return ans;
      |              ^~~
      |              |
      |              vector<long long int>
molecules.cpp:26:14: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   26 |       return ans;
      |              ^~~
      |              |
      |              vector<long long int>
molecules.cpp:36:18: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   36 |           return ans;
      |                  ^~~
      |                  |
      |                  vector<long long int>