답안 #1062130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062130 2024-08-16T19:36:33 Z Hectorungo_18 Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

mt19937 gnd(time(nullptr));

// #define int long long
vector<int> find_subset(int l, int r, vector<int> w){
    int n = w.size();
    vector<pair<int, int>> v(n);
    for(int i = 0; i < n; i++){
        v[i]={w[i], i};
    }
    sort(v.begin(), v.end());

    int aux = 0;
    vector<int> ba, bb;
    for(int i = 0; i < n; i++){
        ba[i]=v[i].first;
        bb[i]=v[i].second;
    }
    vector<int> sol;
    for(int i = n-1; i >= 0; i--){
        if(ba[i] > r) continue;
        sol.clear();
        sol.push_back(bb[i]);
        aux = ba[i];
        bool im = 0;
        int fal = l-aux;
        int cp = i;

        while(l > aux){
            fal = r-aux;
            auto it = upper_bound(ba.begin(), ba.begin()+cp, fal);
            if(it == ba.begin()+cp || it == ba.begin()){
                im = 0;
                break;
            }
            else{
                cp = it-ba.begin()-1;
                aux+=ba[cp];
                sol.push_back(bb[cp]);
            }
            if(aux >= l && aux <= r) break;
            cp++;
            if(cp == 0){
                im = 0;
                break;
            }
        }
        if(im == 0) continue;
        if(aux <= l && aux >= r) break;


    }
    if(aux < l || aux > r){
        sol.clear();
    }
    return sol;
    
    
    
    
}


signed main() {
//   ios::sync_with_stdio(false); cin.tie(nullptr); 


    while(1){
        int n = gnd()%2000+3;
        vector<int> v(n);
        for(int i = 0; i < n; i++){
            v[i]=gnd()%1000000+1;
        }
        sort(v.begin(), v.end());
        int l = gnd()%1000000+1;
        int r = gnd()%500000+1+v[n-1]-v[0]+l;
        vector<int> a = find_subset(l, r, v), b = find(l, r, v);
        if(min(a.size(), b.size()) == 0 && max(a.size(), b.size()) > 0){
            cout << "FOUND  " << endl;
            cout << n << " " << l << " " << r << endl;
            for(auto x : v) cout << x <<" ";
            cout << endl;
            for(auto x : a) cout << x <<" ";
            cout << endl;
            for(auto x : b) cout << x <<" ";
            cout << endl;

            return 0;
        }

    }
}

Compilation message

molecules.cpp: In function 'int main()':
molecules.cpp:79:55: error: conversion from 'int' to non-scalar type 'std::vector<int>' requested
   79 |         vector<int> a = find_subset(l, r, v), b = find(l, r, v);
      |                                                   ~~~~^~~~~~~~~
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h: In instantiation of '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const std::vector<int> >]':
/usr/include/c++/10/bits/stl_algo.h:3902:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = std::vector<int>]'
molecules.cpp:79:63:   required from here
/usr/include/c++/10/bits/stl_algobase.h:1978:34: error: no matching function for call to '__iterator_category(int&)'
 1978 |          std::__iterator_category(__first));
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:65,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_types.h:238:5: note: candidate: 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&)'
  238 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_iterator_base_types.h:238:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_iterator_base_types.h: In substitution of 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&) [with _Iter = int]':
/usr/include/c++/10/bits/stl_algobase.h:1978:34:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const std::vector<int> >]'
/usr/include/c++/10/bits/stl_algo.h:3902:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = std::vector<int>]'
molecules.cpp:79:63:   required from here
/usr/include/c++/10/bits/stl_iterator_base_types.h:238:5: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'