제출 #875769

#제출 시각아이디문제언어결과실행 시간메모리
875769raul2008487Detecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #include "molecules.h" #define ll long long #define all(v) v.begin(), v.end() #define pb push_back #define fi first #define se second #define vl vector<ll> using namespace std; bool check(ll cur, ll low, ll high){ return (cur <= high && cur >= low); } vector<int> find_subset(int l, int u, vector<int> w) { vl ans; vector<pair<ll,ll>> p; ll i, j, n = w.size(), left = 0, right = 1; long long sum = w[0]; for(i=0;i<n;i++){ p.pb({w[i], i}); } sort(all(p)); bool flag = 0; while(left <= right){ if(check(sum, l, u)){ break; } else if(sum > u){ if(left == n){ flag = 1; break; } sum -= p[left].fi; left++; } else if(sum < l){ if(right == n){ flag = 1; break; } sum += p[right].fi; right++; } } if(flag){ return ans; } else{ for(i=left;i<right;i++){ ans.pb(p[i].se); } return ans; } }

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:45:16: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   45 |         return ans;
      |                ^~~
      |                |
      |                vector<long long int>
molecules.cpp:51:16: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   51 |         return ans;
      |                ^~~
      |                |
      |                vector<long long int>
molecules.cpp:16:11: warning: unused variable 'j' [-Wunused-variable]
   16 |     ll i, j, n = w.size(), left = 0, right = 1;
      |           ^