제출 #1356586

#제출 시각아이디문제언어결과실행 시간메모리
1356586dreamofsecretuniverseDetecting Molecules (IOI16_molecules)C++20
컴파일 에러
0 ms0 KiB
#include "molecules.h"

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    vector<int> res;
    vector<pair<int, int>> a;
    int n = w.size();
    for(int i = 0; i < n; ++i) a.emplace_back(w[i], i);
    int i = 0, j = 0;
    sort(a.begin(), a.end());
    int cur = 0;
    while(j<n){
        cur += a[j].first;
        while(cur>u){
            cur -= a[i].first;
            ++i;
        }
        if(cur>=l){
            for(int k = i; k <= j; ++k){
                res.push_back(a[k].second);
            }
            break;
        }
        ++j;
    }
    return res;
}

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:4:5: error: 'vector' was not declared in this scope
    4 |     vector<int> res;
      |     ^~~~~~
molecules.cpp:4:5: note: suggested alternatives:
In file included from /usr/include/c++/13/vector:66,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
molecules.cpp:4:12: error: expected primary-expression before 'int'
    4 |     vector<int> res;
      |            ^~~
molecules.cpp:5:12: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    5 |     vector<pair<int, int>> a;
      |            ^~~~
      |            std::pair
In file included from /usr/include/c++/13/bits/stl_algobase.h:64,
                 from /usr/include/c++/13/vector:62:
/usr/include/c++/13/bits/stl_pair.h:187:12: note: 'std::pair' declared here
  187 |     struct pair
      |            ^~~~
molecules.cpp:5:17: error: expected primary-expression before 'int'
    5 |     vector<pair<int, int>> a;
      |                 ^~~
molecules.cpp:7:32: error: 'a' was not declared in this scope
    7 |     for(int i = 0; i < n; ++i) a.emplace_back(w[i], i);
      |                                ^
molecules.cpp:9:10: error: 'a' was not declared in this scope
    9 |     sort(a.begin(), a.end());
      |          ^
molecules.cpp:9:5: error: 'sort' was not declared in this scope; did you mean 'short'?
    9 |     sort(a.begin(), a.end());
      |     ^~~~
      |     short
molecules.cpp:19:17: error: 'res' was not declared in this scope
   19 |                 res.push_back(a[k].second);
      |                 ^~~
molecules.cpp:25:12: error: 'res' was not declared in this scope
   25 |     return res;
      |            ^~~