結果
問題 | No.2303 Frog on Grid |
ユーザー | umimel |
提出日時 | 2023-05-13 11:47:02 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 2,721 bytes |
コンパイル時間 | 3,791 ms |
コンパイル使用メモリ | 240,248 KB |
実行使用メモリ | 24,200 KB |
最終ジャッジ日時 | 2024-11-29 05:25:16 |
合計ジャッジ時間 | 5,978 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
15,448 KB |
testcase_01 | AC | 35 ms
15,348 KB |
testcase_02 | AC | 65 ms
22,124 KB |
testcase_03 | AC | 53 ms
18,784 KB |
testcase_04 | AC | 66 ms
21,764 KB |
testcase_05 | AC | 69 ms
23,204 KB |
testcase_06 | AC | 53 ms
19,416 KB |
testcase_07 | AC | 66 ms
21,844 KB |
testcase_08 | AC | 68 ms
21,940 KB |
testcase_09 | AC | 44 ms
17,152 KB |
testcase_10 | AC | 49 ms
18,408 KB |
testcase_11 | AC | 45 ms
17,152 KB |
testcase_12 | AC | 54 ms
20,276 KB |
testcase_13 | AC | 36 ms
15,292 KB |
testcase_14 | AC | 38 ms
15,488 KB |
testcase_15 | AC | 36 ms
15,392 KB |
testcase_16 | AC | 36 ms
15,428 KB |
testcase_17 | AC | 40 ms
15,360 KB |
testcase_18 | AC | 75 ms
24,076 KB |
testcase_19 | AC | 73 ms
24,076 KB |
testcase_20 | AC | 73 ms
24,076 KB |
testcase_21 | AC | 70 ms
24,076 KB |
testcase_22 | AC | 70 ms
24,200 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; }