結果
問題 | No.2303 Frog on Grid |
ユーザー | umimel |
提出日時 | 2023-05-13 11:47:02 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 2,721 bytes |
コンパイル時間 | 3,927 ms |
コンパイル使用メモリ | 239,532 KB |
実行使用メモリ | 24,208 KB |
最終ジャッジ日時 | 2024-05-06 19:39:46 |
合計ジャッジ時間 | 6,042 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
15,404 KB |
testcase_01 | AC | 37 ms
15,316 KB |
testcase_02 | AC | 70 ms
22,128 KB |
testcase_03 | AC | 53 ms
18,784 KB |
testcase_04 | AC | 65 ms
21,764 KB |
testcase_05 | AC | 72 ms
23,080 KB |
testcase_06 | AC | 54 ms
19,416 KB |
testcase_07 | AC | 69 ms
21,832 KB |
testcase_08 | AC | 65 ms
22,068 KB |
testcase_09 | AC | 44 ms
17,156 KB |
testcase_10 | AC | 49 ms
18,412 KB |
testcase_11 | AC | 44 ms
17,152 KB |
testcase_12 | AC | 53 ms
20,188 KB |
testcase_13 | AC | 36 ms
15,468 KB |
testcase_14 | AC | 36 ms
15,300 KB |
testcase_15 | AC | 36 ms
15,440 KB |
testcase_16 | AC | 37 ms
15,412 KB |
testcase_17 | AC | 36 ms
15,316 KB |
testcase_18 | AC | 69 ms
24,208 KB |
testcase_19 | AC | 71 ms
24,076 KB |
testcase_20 | AC | 74 ms
24,076 KB |
testcase_21 | AC | 71 ms
24,200 KB |
testcase_22 | AC | 72 ms
24,080 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using pll = pair<ll, ll>; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll LINF = 1LL << 60; const int IINF = 1 << 30; template<typename T> struct Edge{ int to; T w; Edge(int to_, T w_=1){ to = to_; w=w_; } }; template<typename T> using Tree = vector<vector<Edge<T>>>; template<typename T> using Graph = vector<vector<Edge<T>>>; /* 容量&重み付きエッジ for Dinic */ template<typename T> struct REdge{ int to; T cap; T cost; int rev; REdge(int to_, T cap_, T cost_=1){ to = to_; cap = cap_; cost = cost_; } REdge(int to_, T cap_, T cost_, int rev_){ to = to_; cap = cap_; cost = cost_; rev = rev_; } }; /* 残余グラフ for Dinic */ template<typename T> using RGraph = vector<vector<REdge<T>>>; ll pow_mod(ll x, ll n, ll mod){ ll ret = 1; while(n > 0){ if(n & 1) ret = (ret*x)%mod; x = x*x%mod; n >>=1; } return ret; } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; ll MOD = MOD998244353; void cominit(){ fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(ll i=2; i<MAX; i++){ fac[i] = fac[i-1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD; finv[i] = finv[i-1] * inv[i] % MOD; } } ll com(ll n, ll k){ if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cominit(); ll h, w; cin >> h >> w; h++; w++; //dp_h[i]:=合計i個の矢印でh-1に到達する組み合わせ //dp_w[i]:=合計i個の矢印でw-1に到達する組み合わせ vector<ll> dp_h(h, 0), dp_w(w, 0); for(ll n2=0; n2<=(h-1)/2; n2++){ ll n1 = (h-1)-n2*2; dp_h[n1+n2] = com(n1+n2, n1)*finv[n1+n2]%MOD; } for(ll n2=0; n2<=(w-1)/2; n2++){ ll n1 = (w-1)-n2*2; dp_w[n1+n2] = com(n1+n2, n1)*finv[n1+n2]%MOD; } vector<ll> a, b; for(ll i=h/2; i<=h-1; i++) a.pb(dp_h[i]); for(ll j=w/2; j<=w-1; j++) b.pb(dp_w[j]); vector<ll> c = convolution<MOD998244353>(a, b); ll ans = 0; for(ll i=h/2+w/2; i<=h+w-2; i++) ans = (ans + fac[i]*c[i-(h/2+w/2)]%MOD)%MOD; cout << ans << endl; }