結果
問題 | No.2230 Good Omen of White Lotus |
ユーザー | AngrySadEight |
提出日時 | 2022-12-08 20:50:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,777 bytes |
コンパイル時間 | 1,256 ms |
コンパイル使用メモリ | 88,236 KB |
実行使用メモリ | 813,896 KB |
最終ジャッジ日時 | 2023-09-27 12:32:51 |
合計ジャッジ時間 | 7,222 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | AC | 49 ms
6,940 KB |
testcase_15 | AC | 4 ms
5,460 KB |
testcase_16 | AC | 74 ms
7,848 KB |
testcase_17 | AC | 75 ms
7,920 KB |
testcase_18 | AC | 75 ms
7,724 KB |
testcase_19 | AC | 74 ms
7,920 KB |
testcase_20 | AC | 6 ms
4,384 KB |
testcase_21 | AC | 2 ms
4,380 KB |
testcase_22 | AC | 8 ms
4,376 KB |
testcase_23 | AC | 8 ms
4,376 KB |
testcase_24 | MLE | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
ソースコード
#include <iostream> #include <vector> #include <map> using namespace std; typedef long long ll; ll my_pow(ll x, ll n, ll mod){ ll ret; if (n == 0){ ret = 1; } else if (n % 2 == 1){ ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod; } else{ ret = my_pow((x * x) % mod, n / 2, mod); } return ret; } ll inv(ll x, ll mod){ return my_pow(x, mod - 2, mod); } ll mod2 = 998244353; int main(){ ll H,W,N,P; cin >> H >> W >> N >> P; vector<ll> x(N); vector<ll> y(N); for (ll i = 0; i < N; i++){ cin >> x[i] >> y[i]; x[i]--; y[i]--; } vector<vector<bool>> has(H, vector<bool>(W, false)); for (ll i = 0; i < N; i++){ has[x[i]][y[i]] = true; } ll INF = 1000000000; vector<vector<ll>> dp(H, vector<ll>(W, -INF)); dp[0][0] = 0; for (ll i = 0; i < H; i++){ for (ll j = 0; j < W; j++){ if (has[i][j]){ if (i > 0){ dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1); } if (j > 0){ dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1); } } else{ if (i > 0){ dp[i][j] = max(dp[i][j], dp[i - 1][j]); } if (j > 0){ dp[i][j] = max(dp[i][j], dp[i][j - 1]); } } } } ll max_omen = dp[H - 1][W - 1]; //cout << max_omen << endl; ll ans = (my_pow(P, H + W - 3, mod2)); ans = (ans - ((my_pow(P - 1, H + W - 3 - max_omen, mod2)) * (my_pow(P - 2, max_omen, mod2))) % mod2 + mod2) % mod2; ans = (ans * inv((my_pow(P, H + W - 3, mod2)), mod2)) % mod2; cout << ans << endl; }