Submission #1263203

#TimeUsernameProblemLanguageResultExecution timeMemory
1263203silentloopDetecting Molecules (IOI16_molecules)C++20
100 / 100
40 ms6828 KiB
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
#define ll long long

vector<int> find_subset(int l, int u, vector<int> w)
{
    vector<int> ans;
    vector<pair<ll, ll>> v;
    vector<ll> pref;
    ll x, k;
    int i, j;
    for (i = 0; i < sz(w); i++)
        v.pb({w[i], i});
    sort(all(v));
    pref.resize(sz(v), 0);
    pref[0] = v[0].fst;
    for (i = 1; i < sz(v); i++)
    {
        pref[i] = pref[i - 1] + v[i].fst;
    }
    for (i = 0; i < sz(v); i++)
    {
        ll L = i, r = sz(v) - 1, piv, pos = -1, res = 0;
        if (i > 0)
            res = pref[i - 1];
        while (L <= r)
        {
            piv = (L + r) / 2;
            if (pref[piv] - res >= l)
            {
                r = piv - 1;
                pos = piv;
            }
            else
                L = piv + 1;
        }
        if (pos == -1)
            continue;
        if (pref[pos] - res <= u)
        {
            for (k = i; k <= pos; k++)
            {
                ans.pb(v[k].snd);
            }
            return ans;
        }
    }
    return ans;
}

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...