Submission #526226

#TimeUsernameProblemLanguageResultExecution timeMemory
526226pokmui9909Detecting Molecules (IOI16_molecules)C++17
100 / 100
51 ms7236 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll N, L, R;
ll A[200005];
ll S[200005];

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    N = w.size(), L = l, R = u;
    for(int i = 1; i <= N; i++){
        A[i] = i;
    }
    sort(A + 1, A + N + 1, [&](ll p, ll q) -> bool{
        return w[p - 1] < w[q - 1];
    });
    for(int i = 1; i <= N; i++){
        S[i] = S[i - 1] + w[A[i] - 1];
    }
    ll k = -1;
    for(int i = 1; i <= N; i++){
        ll p = S[i], q = S[N] - S[N - i];
        if(!(q < L || p > R)){
            k = i;
            break;
        }
    }
    vector<int> V;
    if(k == -1){
        return V;
    }
    for(int i = k; i <= N; i++){
        ll v = S[i] - S[i - k];
        if(L <= v && v <= R){
            for(int j = 0; j < k; j++){
                V.push_back(A[i - j] - 1);
            }
            return V;
        }
    }
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
#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...