Submission #405192

#TimeUsernameProblemLanguageResultExecution timeMemory
405192FalconBootfall (IZhO17_bootfall)C++17
100 / 100
746 ms3908 KiB
#include <bits/stdc++.h> #ifdef DEBUG #include "debug.hpp" #endif using namespace std; #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); ++it) #define rep(i, N) for(int i = 0; i < (N); ++i) #define rrep(i, N) for(int i = (N) - 1; i >= 0; --i) #define rep1(i, N) for(int i = 1; i <= (N); ++i) #define rep2(i, s, e) for(int i = (s); i <= (e); ++i) #ifdef DEBUG #define debug(x...) { \ ++dbg::depth; \ string dbg_vals = dbg::to_string(x); \ --dbg::depth; \ dbg::fprint(__func__, __LINE__, #x, dbg_vals); \ } #define light_debug(x) { \ dbg::light = true; \ dbg::dout << __func__ << ":" << __LINE__; \ dbg::dout << " " << #x << " = " << x << endl; \ dbg::light = false; \ } #else #define debug(x...) 42 #define light_debug(x) 42 #endif using ll = long long; template<typename T> inline T& ckmin(T& a, T b) { return a = a > b ? b : a; } template<typename T> inline T& ckmax(T& a, T b) { return a = a < b ? b : a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; int s{accumulate(all(a), 0)}; vector<long long> ways(s + 1); ways[0] = 1; auto add = [&](int x) { rrep(i, int(ways.size())) if(i - x >= 0) ways[i] += ways[i - x]; }; auto remove = [&](int x) { rep(i, int(ways.size())) if(i - x >= 0) ways[i] -= ways[i - x]; }; rep(i, n) add(a[i]); debug(ways); if(s % 2 != 0 || ways[s / 2] == 0) return cout << 0 << '\n', 0; vector<int> c(s + 1); vector<bool> b(s + 1); rep(i, n) { remove(a[i]); rep(x, int(ways.size())) { if(ways[x] == 0) continue; b[abs(s - a[i] - 2 * x)] = true; } rep(x, int(c.size())) if(b[x]) ++c[x], b[x] = false; debug(i, ways); add(a[i]); } cout << count_if(all(c), [&](int x) { return x == n; }) << '\n'; rep(i, int(c.size())) if(c[i] == n) cout << i << ' '; cout << '\n'; #ifdef DEBUG dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC << "ms" << endl; #endif return 0; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
bootfall.cpp:69:5: note: in expansion of macro 'debug'
   69 |     debug(ways);
      |     ^~~~~
bootfall.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
bootfall.cpp:85:9: note: in expansion of macro 'debug'
   85 |         debug(i, ways);
      |         ^~~~~
#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...