Submission #1283416

#TimeUsernameProblemLanguageResultExecution timeMemory
1283416LeynaDetecting Molecules (IOI16_molecules)C++20
100 / 100
36 ms6176 KiB
#include "molecules.h"
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();
    vector<pair<ll, ll>> weights;
    for (int i=0; i<n; i++) weights.push_back({w[i], i});
    int left = 0, right = 1;
    sort(all(weights));
    ll sum = weights[0].first;
    bool possible = false;
    while (left < right && (right < n || (right == n && sum >= l))){
        if (sum < l){
            sum += weights[right++].first;
        }
        else if (sum > u){
            sum -= weights[left++].first;
        }
        else{
            possible = true;
            break;
        }
    }
    //cerr << left << " " << right << endl;
    //cerr << "possible: " << possible << endl;
    vector<int> result;
    if (possible){
        for (int i=left; i<right; i++){
            result.push_back(weights[i].second);
        }
    }
    return result;
}

Compilation message (stderr)

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
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...