Submission #648713

#TimeUsernameProblemLanguageResultExecution timeMemory
648713ghostwriterBootfall (IZhO17_bootfall)C++14
100 / 100
719 ms3472 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #else #define debug(...) #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ const int M = 1e9 + 7; const int N = 502; const int NxN = 25e4 + 1; int n, a[N], c[NxN], d[NxN], sum = 0; vi ans; void add(int x) { FOS(i, NxN - 1, x) d[i] = (d[i] + d[i - x]) % M; } void del(int x) { FOR(i, x, NxN - 1) d[i] = (d[i] - d[i - x] + M) % M; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n; FOR(i, 1, n) { cin >> a[i]; sum += a[i]; } if (sum & 1) { cout << 0; return 0; } d[0] = 1; FOR(i, 1, n) add(a[i]); if (!d[sum / 2]) { cout << 0; return 0; } FOR(i, 1, NxN - 1) c[i] = 1; FOR(i, 1, n) { del(a[i]); FOR(j, 1, NxN - 1) { if (!c[j]) continue; int tmp = sum - a[i] + j; if (tmp & 1) { c[j] = 0; continue; } if (!d[tmp / 2]) c[j] = 0; } add(a[i]); } FOR(i, 1, NxN - 1) if (c[i]) ans.pb(i); cout << sz(ans) << '\n'; EACH(i, ans) cout << i << ' '; return 0; } /* 4 1 3 1 5 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

Compilation message (stderr)

bootfall.cpp: In function 'void add(int)':
bootfall.cpp:33:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   33 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
bootfall.cpp:56:19: note: in expansion of macro 'FOS'
   56 | void add(int x) { FOS(i, NxN - 1, x) d[i] = (d[i] + d[i - x]) % M; }
      |                   ^~~
bootfall.cpp: In function 'void del(int)':
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:57:19: note: in expansion of macro 'FOR'
   57 | void del(int x) { FOR(i, x, NxN - 1) d[i] = (d[i] - d[i - x] + M) % M; }
      |                   ^~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:63:5: note: in expansion of macro 'FOR'
   63 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:72:5: note: in expansion of macro 'FOR'
   72 |     FOR(i, 1, n) add(a[i]);
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:77:5: note: in expansion of macro 'FOR'
   77 |     FOR(i, 1, NxN - 1) c[i] = 1;
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:78:5: note: in expansion of macro 'FOR'
   78 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:80:6: note: in expansion of macro 'FOR'
   80 |      FOR(j, 1, NxN - 1) {
      |      ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:91:5: note: in expansion of macro 'FOR'
   91 |     FOR(i, 1, NxN - 1)
      |     ^~~
bootfall.cpp:36:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bootfall.cpp:95:5: note: in expansion of macro 'EACH'
   95 |     EACH(i, ans) cout << i << ' ';
      |     ^~~~
#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...