답안 #1062129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062129 2024-08-16T19:36:10 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;
    }
    int aux = 0;
    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;
    
    
    
    
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:21:9: error: redeclaration of 'int aux'
   21 |     int aux = 0;
      |         ^~~
molecules.cpp:15:9: note: 'int aux' previously declared here
   15 |     int aux = 0;
      |         ^~~