Submission #648645

#TimeUsernameProblemLanguageResultExecution timeMemory
648645ghostwriterBootfall (IZhO17_bootfall)C++17
28 / 100
1097 ms20328 KiB
#pragma GCC optimize ("Ofast") #pragma GCC target ("avx2") #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 db PI = acos(-1); typedef complex<double> cd; typedef vector<cd> pn; void fft(pn &a, bool inv) { int n = sz(a), rev = 0; FOR(i, 1, n - 1) { int j = n >> 1; WHILE(rev & j) { rev ^= j; j >>= 1; } rev ^= j; if (i < rev) swap(a[i], a[rev]); } for (int i = 2; i <= n; i <<= 1) { db ang = 2 * PI / i * (inv? -1 : 1); cd wn(cos(ang), sin(ang)); for (int j = 0; j < n; j += i) { cd w(1); for (int z = 0; z < i / 2; ++z) { cd u = a[j + z], v = w * a[j + z + i / 2]; a[j + z] = u + v; a[j + z + i / 2] = u - v; w *= wn; } } } if (inv) FRN(i, n) a[i] /= n; } pn multiply(pn a, pn b) { int n = 1; WHILE(n < sz(a) + sz(b)) n <<= 1; a.resize(n); b.resize(n); fft(a, 0); fft(b, 0); FRN(i, n) a[i] *= b[i]; fft(a, 1); FRN(i, n) a[i] = round(a[i].real()); return a; } const int N = 502; const int NxN = 25e4 + 1; int n, a[N], c[NxN], sum = 0; bitset<NxN> d[N], d1[N]; vi ans; 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][0] = d1[n + 1][0] = 1; FOR(i, 1, n) d[i] = d[i - 1] | (d[i - 1] << a[i]); if (!d[n][sum / 2]) { cout << 0; return 0; } FOS(i, n, 1) d1[i] = d1[i + 1] | (d1[i + 1] << a[i]); FOR(i, 1, 500 * n) c[i] = 1; FOR(i, 1, n) { pn p(500 * (i - 1) + 1, 0), p1(500 * (n - i) + 1, 0); FOR(j, 0, 500 * (i - 1)) p[j] = d[i - 1][j]; FOR(j, 0, 500 * (n - i)) p1[j] = d1[i + 1][j]; p = multiply(p, p1); FOR(j, 1, 500 * n) { if (!c[j]) continue; int tmp = sum + j - a[i]; if (tmp & 1) { c[j] = 0; continue; } tmp /= 2; if (tmp >= sz(p)) c[j] = 0; else { tmp = p[tmp].real(); if (!tmp) c[j] = 0; } } } FOR(i, 1, 500 * n) { if (!c[i]) continue; 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 fft(pn&, bool)':
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:58:2: note: in expansion of macro 'FOR'
   58 |  FOR(i, 1, n - 1) {
      |  ^~~
bootfall.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:80:11: note: in expansion of macro 'FRN'
   80 |  if (inv) FRN(i, n) a[i] /= n;
      |           ^~~
bootfall.cpp: In function 'pn multiply(pn, pn)':
bootfall.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:89:2: note: in expansion of macro 'FRN'
   89 |  FRN(i, n) a[i] *= b[i];
      |  ^~~
bootfall.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:91:2: note: in expansion of macro 'FRN'
   91 |  FRN(i, n) a[i] = round(a[i].real());
      |  ^~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:104:5: note: in expansion of macro 'FOR'
  104 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:113:5: note: in expansion of macro 'FOR'
  113 |     FOR(i, 1, n) d[i] = d[i - 1] | (d[i - 1] << a[i]);
      |     ^~~
bootfall.cpp:35:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   35 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
bootfall.cpp:118:5: note: in expansion of macro 'FOS'
  118 |     FOS(i, n, 1) d1[i] = d1[i + 1] | (d1[i + 1] << a[i]);
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:119:5: note: in expansion of macro 'FOR'
  119 |     FOR(i, 1, 500 * n) c[i] = 1;
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:120:5: note: in expansion of macro 'FOR'
  120 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:122:6: note: in expansion of macro 'FOR'
  122 |      FOR(j, 0, 500 * (i - 1)) p[j] = d[i - 1][j];
      |      ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:123:6: note: in expansion of macro 'FOR'
  123 |      FOR(j, 0, 500 * (n - i)) p1[j] = d1[i + 1][j];
      |      ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:125:6: note: in expansion of macro 'FOR'
  125 |      FOR(j, 1, 500 * n) {
      |      ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:140:5: note: in expansion of macro 'FOR'
  140 |     FOR(i, 1, 500 * n) {
      |     ^~~
bootfall.cpp:38:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   38 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bootfall.cpp:145:5: note: in expansion of macro 'EACH'
  145 |     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...