제출 #1343350

#제출 시각아이디문제언어결과실행 시간메모리
1343350retardeDetecting Molecules (IOI16_molecules)C++20
컴파일 에러
0 ms0 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

std::vector<int> find_subset(int l, int u, std::vector<int> v) {
    vector<int> ans; int n = (int)v.size();
    for (int i = 0; i < (int)v.size(); i++) {
        if (v[i] >= l && v[i] <= u) {
            ans.push_back(i);
            return ans;
        }
    }

    vector<pair<int, int>> w;
    for (int i = 0; i < n; i++) w.push_back({v[i], i});

    sort(w.begin(), w.end());
    for (int i = 0; i < n; i++) {
        vector<int> tmp; int cs = 0;
        for (int j = i; j < n; j++) {
            cs += w[j].first;
            tmp.push_back(w[j].second);
            if (cs >= l && cs <= u) {
                return tmp;
            }
        }
    }

    vector<int> ans; return ans;
}

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:29:17: error: redeclaration of 'std::vector<int> ans'
   29 |     vector<int> ans; return ans;
      |                 ^~~
molecules.cpp:6:17: note: 'std::vector<int> ans' previously declared here
    6 |     vector<int> ans; int n = (int)v.size();
      |                 ^~~