結果

問題 No.1916 Making Palindrome on Gird
ユーザー siganaisiganai
提出日時 2022-05-01 18:00:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,695 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 213,932 KB
最終ジャッジ日時 2023-09-13 10:21:24
合計ジャッジ時間 11,419 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
78,528 KB
testcase_01 AC 141 ms
78,564 KB
testcase_02 AC 151 ms
80,264 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 145 ms
79,896 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 140 ms
78,736 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 233 ms
113,852 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 266 ms
208,372 KB
testcase_24 AC 265 ms
208,324 KB
testcase_25 AC 270 ms
208,476 KB
testcase_26 AC 265 ms
209,372 KB
testcase_27 AC 263 ms
208,748 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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())
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][gw] == 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)
0