제출 #900085

#제출 시각아이디문제언어결과실행 시간메모리
900085mannshah1211Detecting Molecules (IOI16_molecules)C++14
컴파일 에러
0 ms0 KiB
#include "molecules.h"
using namespace std;

#define int long long 
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
vector<int> find_subset(int l, int u, vector<int> w) {
	  if (accumulate(all(w), 0LL) < l) {
	  	return {};
	  }
    vector<pair<int, int>> indices;
    for (int i = 0; i < w.size(); i++) {
    	indices.pb({w[i], i});
    }
    if (indices[0].f > u) {
    	return {};
    }
    sort(all(indices));
    int cursum = 0, longest = 0;
    for (int i = 0; i < indices.size(); i++) {
    	cursum += indices[i].f;
    	if (cursum >= l) {
    		cursum -= indices[i].f, longest = i;
    		break;
    	}
    }
    for (int i = longest; i < indices.size(); i++) {
    	cursum += indices[i].f;
    	cursum -= indices[i - longest].f;
    	if (cursum >= l && cursum <= u) {
    		vector<int> answer;
    		for (int j = i; j >= i - longest + 1; j--) {
    			answer.pb(indices[j].s);
    		}
    		return answer;
    	}
    }
    return {};
}

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

molecules.cpp: In function 'std::vector<long long int> find_subset(long long int, long long int, std::vector<long long int>)':
molecules.cpp:10:8: error: 'accumulate' was not declared in this scope
   10 |    if (accumulate(all(w), 0LL) < l) {
      |        ^~~~~~~~~~
molecules.cpp:14:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < w.size(); i++) {
      |                     ~~^~~~~~~~~~
molecules.cpp:20:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   20 |     sort(all(indices));
      |     ^~~~
      |     short
molecules.cpp:22:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < indices.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
molecules.cpp:29:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i = longest; i < indices.size(); i++) {
      |                           ~~^~~~~~~~~~~~~~~~