結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | siganai |
提出日時 | 2022-05-01 18:06:35 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 471 ms / 3,000 ms |
コード長 | 1,735 bytes |
コンパイル時間 | 411 ms |
コンパイル使用メモリ | 86,616 KB |
実行使用メモリ | 213,620 KB |
最終ジャッジ日時 | 2023-09-13 10:29:33 |
合計ジャッジ時間 | 11,300 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 144 ms
78,808 KB |
testcase_01 | AC | 143 ms
78,628 KB |
testcase_02 | AC | 161 ms
80,176 KB |
testcase_03 | AC | 143 ms
78,624 KB |
testcase_04 | AC | 150 ms
79,560 KB |
testcase_05 | AC | 149 ms
79,964 KB |
testcase_06 | AC | 155 ms
80,000 KB |
testcase_07 | AC | 152 ms
79,600 KB |
testcase_08 | AC | 154 ms
79,764 KB |
testcase_09 | AC | 145 ms
78,392 KB |
testcase_10 | AC | 143 ms
78,388 KB |
testcase_11 | AC | 153 ms
79,684 KB |
testcase_12 | AC | 143 ms
78,740 KB |
testcase_13 | AC | 275 ms
123,676 KB |
testcase_14 | AC | 237 ms
114,140 KB |
testcase_15 | AC | 314 ms
139,200 KB |
testcase_16 | AC | 261 ms
108,204 KB |
testcase_17 | AC | 399 ms
192,232 KB |
testcase_18 | AC | 447 ms
213,596 KB |
testcase_19 | AC | 454 ms
213,464 KB |
testcase_20 | AC | 444 ms
213,380 KB |
testcase_21 | AC | 457 ms
213,556 KB |
testcase_22 | AC | 446 ms
213,556 KB |
testcase_23 | AC | 272 ms
208,676 KB |
testcase_24 | AC | 278 ms
208,712 KB |
testcase_25 | AC | 277 ms
208,412 KB |
testcase_26 | AC | 275 ms
209,304 KB |
testcase_27 | AC | 273 ms
208,504 KB |
testcase_28 | AC | 470 ms
213,368 KB |
testcase_29 | AC | 469 ms
213,376 KB |
testcase_30 | AC | 467 ms
213,124 KB |
testcase_31 | AC | 471 ms
213,428 KB |
testcase_32 | AC | 470 ms
213,620 KB |
ソースコード
#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=10 ** 9 + 7 import sys input=sys.stdin.readline h,w=map(int,input().split()) if h == w == 1: print(1) exit() s=[input().rstrip() for _ in range(h)] dp = [[[0] * h for _ in range(h)] for _ in range(h + w - 1)] if s[0][0] == s[-1][-1]: dp[0][0][h-1] = 1 ans = 0 for i in range(1,(h+w-1) // 2 + 1): for sh in range(h): sw = i - sh if 0 <= sh < h and 0 <= sw < w: for gh in range(h): gw = h + w - 2 - i - gh if 0 <= gh < h and 0 <= gw < w: if s[sh][sw] == s[gh][gw]: tmp1 = 0 if sh > 0 and gh < h - 1: tmp1 += dp[i-1][sh - 1][gh + 1] if sh > 0 and gw < w - 1: tmp1 += dp[i-1][sh-1][gh] tmp1 %= mod if sw > 0 and gh < h - 1: tmp1 += dp[i-1][sh][gh + 1] tmp1 %= mod if sw > 0 and gw < w - 1: tmp1 += dp[i-1][sh][gh] tmp1 %= mod if gh >= sh and gw >= sw and gh + gw - sh - sw <= 1: ans += tmp1 ans %= mod else: dp[i][sh][gh] = tmp1 print(ans) #print(dp) else: print(0)