Submission #392443

#TimeUsernameProblemLanguageResultExecution timeMemory
392443usachevd0Detecting Molecules (IOI16_molecules)C++17
100 / 100
57 ms6724 KiB
#include <bits/stdc++.h> #ifndef DEBUG #include "molecules.h" #endif // DEBUG 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) { ll L = _L, R = _R; int n = _w.size(); vector<pli> w(n); for (int i = 0; i < n; ++i) { w[i] = {_w[i], i}; } debug(n); sort(all(w)); ll S = 0; for (int i = 0; i < n; ++i) S += w[i].fi; if (S < L) { return vector<int>(); } if (S <= R) { vector<int> ans(n); iota(all(ans), 0); return ans; } if (n <= 1) { return vector<int>(); } int p = n; ll suff = 0; ll pref = S - w[n - 1].fi; debug(pref); for (int i = n - 2; i >= -1; --i) { debug(i, pref); while (p - 1 > i && suff + w[p - 1].fi + pref <= R) { suff += w[--p].fi; } if (pref + suff >= L && pref + suff <= R) { debug(pref, suff, i, p); vector<int> ans; for (int j = 0; j <= i; ++j) ans.pb(w[j].se); for (int j = p; j < n; ++j) ans.pb(w[j].se); ll s = 0; for (int j : ans) s += w[j].fi; debug(s); return ans; } if (i >= 0) pref -= w[i].fi; } return vector<int>(); } #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]]; debug(sum); 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:43:22: warning: statement has no effect [-Wunused-value]
   43 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:63:5: note: in expansion of macro 'debug'
   63 |     debug(n);
      |     ^~~~~
molecules.cpp:43:22: warning: statement has no effect [-Wunused-value]
   43 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:81:5: note: in expansion of macro 'debug'
   81 |     debug(pref);
      |     ^~~~~
molecules.cpp:43:22: warning: statement has no effect [-Wunused-value]
   43 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:83:9: note: in expansion of macro 'debug'
   83 |         debug(i, pref);
      |         ^~~~~
molecules.cpp:43:22: warning: statement has no effect [-Wunused-value]
   43 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:88:13: note: in expansion of macro 'debug'
   88 |             debug(pref, suff, i, p);
      |             ^~~~~
molecules.cpp:43:22: warning: statement has no effect [-Wunused-value]
   43 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:96:13: note: in expansion of macro 'debug'
   96 |             debug(s);
      |             ^~~~~
#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...