Submission #418063

#TimeUsernameProblemLanguageResultExecution timeMemory
418063JerryLiu06Bootfall (IZhO17_bootfall)C++17
100 / 100
578 ms2756 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() #define bg(x) begin(x) #define all(x) bg(x), end(x) #define sor(x) sort(all(x)) #define ft front() #define bk back() #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define EACH(a,x) for (auto& a: x) const int MOD = 1e9 + 7; const int MX = 510; const ll INF = 1e18; int N, A[MX], tot; int DP[MX * MX]; bitset<MX * MX> ans; void ADD(int val) { tot += val; ROF(i, val, MX * MX) { DP[i] += DP[i - val]; if (DP[i] > MOD) DP[i] -= MOD; } } void DEL(int val) { tot -= val; FOR(i, val, MX * MX) { DP[i] -= DP[i - val]; if (DP[i] < 0) DP[i] += MOD; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ans.flip(); cin >> N; DP[0] = 1; F0R(i, N) cin >> A[i], ADD(A[i]); // Case when Tima is the recorder if (tot % 2 == 1 || !DP[tot / 2]) { cout << "0" << "\n"; return 0; } F0R(i, N) { DEL(A[i]); bitset<MX * MX> cur; F0R(j, tot / 2 + 1) if (DP[j]) cur[tot - 2 * j] = 1; ADD(A[i]); ans &= cur; } vi res; FOR(i, 1, MX * MX) if (ans[i]) res.pb(i); cout << sz(res) << "\n"; EACH(i, res) cout << i << " "; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:39:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   39 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                    ^~~
bootfall.cpp:40:18: note: in expansion of macro 'FOR'
   40 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
bootfall.cpp:73:9: note: in expansion of macro 'F0R'
   73 |         F0R(j, tot / 2 + 1) if (DP[j]) cur[tot - 2 * j] = 1; ADD(A[i]); ans &= cur;
      |         ^~~
bootfall.cpp:73:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   73 |         F0R(j, tot / 2 + 1) if (DP[j]) cur[tot - 2 * j] = 1; ADD(A[i]); ans &= cur;
      |                                                              ^~~
#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...