Advertisement
pb_jiang

ARC116D

Nov 30th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. // Problem: D - I Wanna Win The Game
  2. // Contest: AtCoder - AtCoder Regular Contest 116
  3. // URL: https://atcoder.jp/contests/arc116/tasks/arc116_d
  4. // Memory Limit: 1024 MB
  5. // Time Limit: 2000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. #include <atcoder/modint>
  12.  
  13. using namespace std;
  14. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  15. template <typename... Args> void logger(string vars, Args &&... values)
  16. {
  17.     cerr << vars << " = ";
  18.     string delim = "";
  19.     (..., (cerr << delim << values, delim = ", "));
  20.     cerr << endl;
  21. }
  22.  
  23. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  24. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  25. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  26. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  27.  
  28. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  29. using vi = vector<int>;
  30. using ll = long long;
  31. using pii = pair<int, int>;
  32. using mint = atcoder::modint998244353;
  33.  
  34. const int mod = 998244353;
  35. int n, m;
  36. vi f;
  37.  
  38. mint comb(int n, int r)
  39. {
  40.     /*
  41.     static auto dp = vv<int>(5001);
  42.     if (dp[n][r] != 0)
  43.         return dp[n][r];
  44.     assert(n >= r);
  45.     int step = min(r, n - r);
  46.     mint ans = 1, ub = n, lb = r;
  47.     for (int i = 0; i < step; ++i) {
  48.         ans *= ub / lb;
  49.         --ub, --lb;
  50.     }
  51.     dp[n][r] = ans.val();
  52.     return ans;
  53.     */
  54.  
  55.     static vi dp(5001);
  56.     if (dp[0] == 0) {
  57.         dp[0] = 1;
  58.         for (int i = 1; i <= n; ++i) {
  59.             for (int j = i; j > 0; --j)
  60.                 dp[j] = (dp[j] + dp[j - 1]) % mod;
  61.         }
  62.     }
  63.     return dp[r];
  64. }
  65.  
  66. int getf(int x)
  67. {
  68.     if (f[x] != -1)
  69.         return f[x];
  70.     if (x % 2)
  71.         return f[x] = 0;
  72.     mint ans = 0;
  73.  
  74.     /*
  75.     WA
  76.     for (int i = min(x, n); i >= 0; i -= 2) {
  77.         ans += getf((x - i) / 2) * comb(n, i);
  78.     }
  79.     */
  80.  
  81.     // AC
  82.     for (int i = 0; i <= min(x, n); i += 2) {
  83.         ans += mint(getf((x - i) / 2)) * comb(n, i);
  84.     }
  85.  
  86.     return f[x] = ans.val();
  87. }
  88.  
  89. int main(int argc, char **argv)
  90. {
  91.     cin >> n >> m;
  92.     f = vi(m + 1, -1);
  93.     f[0] = 1;
  94.     if (m % 2) {
  95.         cout << 0 << endl;
  96.         return 0;
  97.     }
  98.     int ans;
  99.     for (int i = 2; i <= m; ++i)
  100.         ans = getf(i);
  101.     cout << ans << endl;
  102.     return 0;
  103. };
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement