結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー |
👑 ![]() |
提出日時 | 2022-04-29 22:22:44 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,186 bytes |
コンパイル時間 | 349 ms |
コンパイル使用メモリ | 82,228 KB |
実行使用メモリ | 262,584 KB |
最終ジャッジ日時 | 2024-06-29 03:57:33 |
合計ジャッジ時間 | 14,835 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 TLE * 5 |
ソースコード
"""https://yukicoder.me/problems/no/1916dpかな200*200*200?"""import sysfrom sys import stdinH,W = map(int,stdin.readline().split())if H == W == 1:print (1)sys.exit()S = [list(stdin.readline()[:-1]) for i in range(H) ]mod = 10**9+7q = {}if S[0][0] == S[H-1][W-1]:q[(0,0,H-1,W-1)] = 1ans = 0while q:newq = {}for tup in q:x1,y1,x2,y2 = tupcnt = q[tup]for newx1,newy1 in ( (x1+1,y1) , (x1,y1+1) ):for newx2,newy2 in ( (x2-1,y2) , (x2,y2-1) ):fl = (0<=newx1<H and 0<=newy1<W and 0<=newx2<H and 0<=newy2<W)if fl and newx1<=newx2 and newy1<=newy2 and S[newx1][newy1] == S[newx2][newy2]:newtup = (newx1,newy1,newx2,newy2)diff = abs(newx2-newx1) + abs(newy2-newy1)if diff <= 1:ans += cntans %= modelif newtup not in newq:newq[newtup] = cntelse:newq[newtup] += cntnewq[newtup] %= modq = newq#print (q)print (ans % mod)