Submission #392423

#TimeUsernameProblemLanguageResultExecution timeMemory
392423usachevd0Detecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms332 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
  return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
  return y > x ? (x = y, true) : false;
}
void debug_out() {
  cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
  cerr << ' ' << A;
  debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
  for (int i = 0; i < n; ++i) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
#ifdef DEBUG
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
  #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
  #define debug(...) 1337
  #define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& a) {
  for (auto& x : a) {
    stream << x << ' ';
  }
  return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
  return stream << p.first << ' ' << p.second;
}

vector<int> find_subset(int L, int R, vector<int> w) {
    int n = w.size();
    sort(all(w));
    if (accumulate(all(w), 0LL) < L) {
        return {};
    }
    if (accumulate(all(w), 0LL) <= R) {
        vector<int> ans(n);
        iota(all(ans), 0);
        return ans;
    }
    if (n <= 1) {
        return {};
    }
    int p = n;
    ll suff = 0;
    ll pref = accumulate(w.begin(), w.end() - 1, 0LL);
    for (int i = n - 2; i >= -1; --i) {
        while (p - 1 > i && suff + w[p - 1] + pref <= R) {
            suff += w[--p];
        }
        debug(i, p, pref, suff);
        if (pref + suff >= L && pref + suff <= R) {
            vector<int> ans;
            for (int j = 0; j <= i; ++j)
                ans.pb(j);
            for (int j = p; j < n; ++j)
                ans.pb(j);
            ll s = 0;
            for (int j : ans) s += w[j];
            assert(s == pref + suff);
            return ans;
        }
        if (i >= 0) pref -= w[i];
    }
    return {};
}

#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, L, R;
    cin >> n >> L >> R;
    vector<int> w(n);
    for (int i = 0; i < n; ++i) cin >> w[i];
    vector<int> ans = find_subset(L, R, w);
    int m = ans.size();
    debug(m);
    debug(ans);
    ll sum = 0;
    for (int i = 0; i < m; ++i)
        sum += w[ans[i]];
    assert(sum == 0 || L <= sum && sum <= R);

    return 0;
}
#endif

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:40:22: warning: statement has no effect [-Wunused-value]
   40 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:74:9: note: in expansion of macro 'debug'
   74 |         debug(i, p, pref, suff);
      |         ^~~~~
#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...