제출 #1219781

#제출 시각아이디문제언어결과실행 시간메모리
1219781LIADetecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple <ll,ll,ll> plll;
typedef vector <plll> vplll;
typedef pair <ll,ll> pll;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef vector <vector <pll>> vvpll;
typedef vector <vector <ll>> vvll;
typedef vector <bool> vb;
typedef vector <vector <bool>> vvb;
#define loop(i, s, e) for (ll i = (s); i < (e); ++i)
#define loopr(i, e, s) for (ll i = (e)-1; i >= (s); --i)
#define all(a) a.begin(), a.end()
const ll inf = 1e9 + 7;

std::vector<int> find_subset(int l, int r, std::vector<int> w) {
    ll n = w.size();
    multiset<pll, greater<pll>> in;
    vpll v(n);
    vll ansi;
    loop(i,0,n) v[i] = {w[i], i};
    sort(all(v));
    reverse(all(v));
    ll sum = 0;
    ll last_idx;
    loop(i,0,n) {
        if (sum>=l) break;
        auto [num,idx] =  v[i];
        last_idx = i;
        sum+=num;
        in.insert({num,idx});
    }
    if (sum<l ) return {};
    if (sum>=l&& sum<=r) {
        for (auto [num,idx] : in) ansi.push_back(idx);
        return ansi;
    }

    loopr(i,n,last_idx+1) {
        if (sum>=l && sum<=r) {
            for (auto [num,idx] : in) ansi.push_back(idx);
            return ansi;
        }
       else  if (sum>l) {
            auto it = in.begin();
            ll mx_num = it->first, idx = it->second;
            auto [add, ind] = v[i];
            sum+= -mx_num+add;
            in.erase(it);
            in.insert({add,ind});
        }
        else if (sum<l) {
            auto [add, ind] = v[i];
            sum+= add;
            in.insert({add,ind});
        }
    }

    if (sum>=l && sum<=r) {
        for (auto [num,idx] : in) ansi.push_back(idx);
        return ansi;
    }
    return {};

}

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:39:16: error: could not convert 'ansi' from 'vector<long long int>' to 'vector<int>'
   39 |         return ansi;
      |                ^~~~
      |                |
      |                vector<long long int>
molecules.cpp:45:20: error: could not convert 'ansi' from 'vector<long long int>' to 'vector<int>'
   45 |             return ansi;
      |                    ^~~~
      |                    |
      |                    vector<long long int>
molecules.cpp:64:16: error: could not convert 'ansi' from 'vector<long long int>' to 'vector<int>'
   64 |         return ansi;
      |                ^~~~
      |                |
      |                vector<long long int>
molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~