結果
問題 | No.2689 Populous |
ユーザー | 👑 rin204 |
提出日時 | 2024-03-07 21:18:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,197 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 81,908 KB |
実行使用メモリ | 76,672 KB |
最終ジャッジ日時 | 2024-09-29 18:42:01 |
合計ジャッジ時間 | 2,452 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
52,608 KB |
testcase_01 | AC | 34 ms
52,992 KB |
testcase_02 | AC | 34 ms
52,992 KB |
testcase_03 | AC | 34 ms
52,480 KB |
testcase_04 | AC | 34 ms
52,652 KB |
testcase_05 | AC | 33 ms
52,608 KB |
testcase_06 | WA | - |
testcase_07 | AC | 32 ms
52,608 KB |
testcase_08 | WA | - |
testcase_09 | AC | 37 ms
52,736 KB |
testcase_10 | AC | 34 ms
52,480 KB |
testcase_11 | AC | 33 ms
52,480 KB |
testcase_12 | AC | 34 ms
52,864 KB |
testcase_13 | AC | 34 ms
52,864 KB |
testcase_14 | WA | - |
testcase_15 | AC | 34 ms
52,480 KB |
testcase_16 | AC | 33 ms
52,736 KB |
testcase_17 | AC | 32 ms
52,480 KB |
testcase_18 | WA | - |
testcase_19 | AC | 32 ms
52,864 KB |
testcase_20 | AC | 46 ms
64,512 KB |
testcase_21 | AC | 50 ms
64,512 KB |
testcase_22 | AC | 49 ms
64,512 KB |
testcase_23 | AC | 76 ms
76,416 KB |
testcase_24 | AC | 85 ms
76,552 KB |
testcase_25 | AC | 84 ms
76,672 KB |
testcase_26 | AC | 74 ms
76,324 KB |
testcase_27 | AC | 82 ms
76,440 KB |
testcase_28 | AC | 72 ms
76,260 KB |
testcase_29 | AC | 73 ms
76,544 KB |
testcase_30 | AC | 73 ms
76,288 KB |
ソースコード
MOD = 998244353 h, w = map(int, input().split()) assert 3 <= h <= 1000 assert 3 <= w <= 1000 U = list(map(int, input().split())) L = [0] * h R = [0] * h L[0] = U[0] R[0] = U[-1] for i in range(1, h - 1): L[i], R[i] = map(int, input().split()) D = list(map(int, input().split())) L[-1] = D[0] R[-1] = D[-1] for i in range(h - 1): if abs(L[i] - L[i + 1]) > 1: print(-1) exit() if abs(R[i] - R[i + 1]) > 1: print(-1) exit() for i in range(w - 1): if abs(U[i] - U[i + 1]) > 1: print(-1) exit() if abs(D[i] - D[i + 1]) > 1: print(-1) exit() row = False for i in range(h): d = abs(L[i] - R[i]) if d > w - 1: row = True col = False for i in range(w): d = abs(U[i] - D[i]) if d > h - 1: col = True assert not row or not col if not row and not col: print(1) exit() if col: L, R, U, D = U, D, L, R h, w = w, h dp = [0] * (w - 1) dp[-1] = 1 for i in range(1, h - 1): ndp = [0] * (w - 1) d = abs(L[i] - R[i]) if d <= w - 1: ndp[-1] = sum(dp) % MOD dp = ndp continue uu = abs(L[i] - R[i - 1]) > h dd = abs(L[i - 1] - R[i]) > h if uu and dd: for j in range(w - 2): ndp[j] += dp[-1] if j != 0: ndp[j] += dp[j - 1] ndp[j] += dp[j] if j != w - 3: ndp[j] += dp[j + 1] ndp[j] %= MOD elif uu: for j in range(1, w - 2): dp[j] += dp[j - 1] dp[j] %= MOD for j in range(w - 2): ndp[j] += dp[-1] if j != w - 3: ndp[j] += dp[j + 1] else: ndp[j] += dp[j] ndp[j] %= MOD elif dd: for j in range(w - 4, -1, -1): dp[j] += dp[j + 1] dp[j] %= MOD for j in range(w - 2): ndp[j] += dp[-1] if j != 0: ndp[j] += dp[j - 1] else: ndp[j] += dp[j] ndp[j] %= MOD else: tot = sum(dp) % MOD ndp = [tot] * (w - 1) ndp[-1] = 0 dp = ndp ans = sum(dp) % MOD print(ans)