結果
| 問題 | No.1916 Making Palindrome on Gird |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-07-29 12:08:48 |
| 言語 | PyPy3 (8.0.1 + ACL) |
| 結果 |
TLE
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 814 bytes |
| 記録 | |
| コンパイル時間 | 85 ms |
| コンパイル使用メモリ | 64,256 KB |
| 実行使用メモリ | 421,284 KB |
| 最終ジャッジ日時 | 2026-11-29 00:15:19 |
| 合計ジャッジ時間 | 28,719 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge6_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 TLE * 1 |
ソースコード
from itertools import product
from functools import cache
MOD = 10**9 + 7
H, W = map(int, input().split())
S = []
for i in range(H):
S.append(input())
@cache
def f(r1, c1, r2, c2) -> int:
if r1 == r2 and c1 == c2:
return 1
if r1 == r2 and c1+1 == c2:
return 1 if S[r1][c1] == S[r2][c2] else 0
if r1+1 == r2 and c1 == c2:
return 1 if S[r1][c1] == S[r2][c2] else 0
if S[r1][c1] != S[r2][c2]:
return 0
res = 0
for (dr1, dc1), (dr2, dc2) in product([(0, 1), (1, 0)], [(0, -1), (-1, 0)]):
nr1 = r1 + dr1
nc1 = c1 + dc1
nr2 = r2 + dr2
nc2 = c2 + dc2
if nr1 > nr2: continue
if nc1 > nc2: continue
res += f(nr1, nc1, nr2, nc2)
res %= MOD
return res
ans = f(0, 0, H-1, W-1)
print(ans)
norioc