Submission #1354609

#TimeUsernameProblemLanguageResultExecution timeMemory
1354609takoshanavaDetecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "molecules.h"
#define pb push_back
#define fs first
#define sc second
using namespace std;

vector<int> find_subset(int l, int u, vector<int> w) {
    vector<pair<int, int>> p;
    for(int i = 0; i < w.size(); i++) p.pb({w[i], i});
    sort(p.begin(),p.end());

    int n = w.size();
    long long sum = 0;
    int l1 = 0, r = 0;
    while(true){
        if(sum >= l and sum <= u) break;

        if(sum < l){
            if(r == n) break;
            sum += p[r].fs;
            r++;
        }else{
            sum -= p[l1].fs;
            l1++;
        }
    }
    vector<int> ans;
    if(!(sum >= l and sum <= u)) ans;
    vector<int> ans;
    for(int i = l1; i < r; i++) ans.pb(p[i].sc);
    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:30:17: error: redeclaration of 'std::vector<int> ans'
   30 |     vector<int> ans;
      |                 ^~~
molecules.cpp:28:17: note: 'std::vector<int> ans' previously declared here
   28 |     vector<int> ans;
      |                 ^~~