結果
問題 | No.3071 Double Speedrun |
ユーザー |
|
提出日時 | 2025-03-24 04:24:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 6,000 ms |
コード長 | 2,380 bytes |
コンパイル時間 | 2,362 ms |
コンパイル使用メモリ | 201,552 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-24 04:24:16 |
合計ジャッジ時間 | 3,180 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<int MOD> struct ModInt { int x; ModInt() : x(0) {} ModInt(ll v) : x(v % MOD) { if (x < 0) x += MOD; } ModInt operator+(const ModInt &o) const { int r = x + o.x; return r >= MOD ? r - MOD : r; } ModInt operator-(const ModInt &o) const { int r = x - o.x; return r < 0 ? r + MOD : r; } ModInt operator*(const ModInt &o) const { return (ll)x * o.x % MOD; } ModInt operator-() const { return x ? MOD - x : 0; } ModInt& operator+=(const ModInt &o) { if ((x += o.x) >= MOD) x -= MOD; return *this; } ModInt& operator-=(const ModInt &o) { if ((x -= o.x) < 0) x += MOD; return *this; } ModInt& operator*=(const ModInt &o) { x = (ll)x * o.x % MOD; return *this; } ModInt pow(ll e) const { ModInt res(1), b(*this); for (; e; e >>= 1, b *= b) { if (e & 1) res *= b; } return res; } ModInt inv() const { return pow(MOD - 2); } ModInt operator/(const ModInt &o) const { return *this * o.inv(); } ModInt& operator/=(const ModInt &o) { return *this *= o.inv(); } bool operator==(const ModInt &o) const { return x == o.x; } bool operator!=(const ModInt &o) const { return x != o.x; } friend ostream& operator<<(ostream &os, const ModInt &m) { return os << m.x; } }; using mint = ModInt<998244353>; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) cin >> s[i]; vector<vector<mint>> dp1(h, vector<mint>(w, 0)), dp2 = dp1; dp1[0][1] = 1; dp2[1][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; if (i > 0) { dp1[i][j] += dp1[i - 1][j]; dp2[i][j] += dp2[i - 1][j]; } if (j > 0) { dp1[i][j] += dp1[i][j - 1]; dp2[i][j] += dp2[i][j - 1]; } } } mint ans = dp1[h - 2][w - 1] * dp2[h - 1][w - 2] - dp1[h - 1][w - 2] * dp2[h - 2][w - 1]; cout << ans << "\n"; return 0; }