Submission #416956

#TimeUsernameProblemLanguageResultExecution timeMemory
416956yuto1115Detecting Molecules (IOI16_molecules)C++17
100 / 100
56 ms5956 KiB
#include "molecules.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

vi find_subset(int l, int u, vi w) {
    int n = w.size();
    vi ord(n);
    iota(all(ord), 0);
    sort(all(ord), [&](int i, int j) { return w[i] < w[j]; });
    vl ls(n + 1), rs(n + 1);
    rep(i, n) ls[i + 1] = ls[i] + w[ord[i]];
    rrep(i, n) rs[i] = rs[i + 1] + w[ord[i]];
    if (ls[n] < l) return {};
    reverse(all(rs));
    rep(i, n + 1) {
        if (ls[i] > u) break;
        auto it = lower_bound(all(rs), l - ls[i]);
        if (ls[i] + *it > u) continue;
        vi ans;
        rep(j, i) ans.pb(ord[j]);
        rep(j, it - rs.begin()) ans.pb(ord[n - 1 - j]);
        return ans;
    }
    return {};
}
#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...