結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | titia |
提出日時 | 2022-04-29 22:08:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,353 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 86,832 KB |
実行使用メモリ | 266,952 KB |
最終ジャッジ日時 | 2023-09-11 13:23:05 |
合計ジャッジ時間 | 29,764 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
71,592 KB |
testcase_01 | AC | 92 ms
71,432 KB |
testcase_02 | AC | 244 ms
82,728 KB |
testcase_03 | AC | 94 ms
71,568 KB |
testcase_04 | AC | 99 ms
76,228 KB |
testcase_05 | AC | 99 ms
76,236 KB |
testcase_06 | AC | 102 ms
76,240 KB |
testcase_07 | AC | 97 ms
76,244 KB |
testcase_08 | AC | 100 ms
76,300 KB |
testcase_09 | AC | 98 ms
76,032 KB |
testcase_10 | AC | 92 ms
71,564 KB |
testcase_11 | AC | 100 ms
76,300 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 132 ms
78,224 KB |
testcase_15 | WA | - |
testcase_16 | AC | 784 ms
101,392 KB |
testcase_17 | AC | 1,304 ms
143,512 KB |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | AC | 96 ms
71,512 KB |
testcase_24 | AC | 94 ms
71,408 KB |
testcase_25 | AC | 95 ms
71,580 KB |
testcase_26 | AC | 91 ms
71,536 KB |
testcase_27 | AC | 93 ms
71,868 KB |
testcase_28 | TLE | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
import sys input = sys.stdin.readline from collections import defaultdict mod=10**9+7 H,W=map(int,input().split()) MAP=[input().strip() for i in range(H)] if MAP[0][0]!=MAP[-1][-1]: print(0) exit() DP=dict() DP[0,0,H-1,W-1]=1 for i in range((H+W-2)//2): NDP=defaultdict(int) for x,y,z,w in DP: if 0<=x<H and 0<=z<H and 0<=y+1<W and 0<=w-1<W and MAP[x][y+1]==MAP[z][w-1]: NDP[x,y+1,z,w-1]+=DP[x,y,z,w] NDP[x,y+1,z,w-1]%=mod if 0<=x<H and 0<=z-1<H and 0<=y+1<W and 0<=w<W and MAP[x][y+1]==MAP[z-1][w]: NDP[x,y+1,z-1,w]+=DP[x,y,z,w] NDP[x,y+1,z-1,w]%=mod if 0<=x+1<H and 0<=z<H and 0<=y<W and 0<=w-1<W and MAP[x+1][y]==MAP[z][w-1]: NDP[x+1,y,z,w-1]+=DP[x,y,z,w] NDP[x+1,y,z,w-1]%=mod if 0<=x+1<H and 0<=z-1<H and 0<=y<W and 0<=w<W and MAP[x+1][y]==MAP[z-1][w]: NDP[x+1,y,z-1,w]+=DP[x,y,z,w] NDP[x+1,y,z-1,w]%=mod DP=NDP if (H+W)%2==0: ANS=0 for x,y,z,w in DP: if x==z and y==w: ANS+=DP[x,y,z,w] ANS%=mod print(ANS) else: ANS=0 for x,y,z,w in DP: if x==z and y+1==w: ANS+=DP[x,y,z,w] ANS%=mod if x+1==-z and y==w: ANS+=DP[x,y,z,w] ANS%=mod print(ANS)