結果

問題 No.1561 connect x connect
ユーザー uwiuwi
提出日時 2020-11-27 03:01:54
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,259 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 267,844 KB
最終ジャッジ日時 2023-09-07 13:52:22
合計ジャッジ時間 13,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 217 ms
92,880 KB
testcase_01 AC 320 ms
93,472 KB
testcase_02 AC 947 ms
117,308 KB
testcase_03 AC 221 ms
88,392 KB
testcase_04 AC 230 ms
88,272 KB
testcase_05 AC 232 ms
88,668 KB
testcase_06 AC 223 ms
88,440 KB
testcase_07 AC 263 ms
91,668 KB
testcase_08 AC 323 ms
93,684 KB
testcase_09 AC 378 ms
94,276 KB
testcase_10 AC 377 ms
94,208 KB
testcase_11 AC 469 ms
96,372 KB
testcase_12 AC 541 ms
99,112 KB
testcase_13 AC 798 ms
110,328 KB
testcase_14 AC 785 ms
135,244 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import dataclasses
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()


@dataclasses.dataclass
class State:
    clus: [int]
    val: int
    hidden: int

    def h(self):
        return (*self.clus, self.hidden)

MOD = 1000000007

def normalize(a: [int]) -> [int]:
    label = [-1] * 11
    p = 0
    for i in range(len(a)):
        if a[i] == -1:
            continue
        if label[a[i]] == -1:
            label[a[i]] = p
            p += 1
        a[i] = label[a[i]]
    return a

def add(s: State, dp: [int, State]):
    key = s.h()
    if key in dp:
        dp[key].val = (dp[key].val + s.val) % MOD
    else:
        dp[key] = s

n, m = na()
initial = State([-1] * n, 1, 0)
dp: [int, State] = dict()
dp[initial.h()] = initial

for j in range(m+1):
    for i in range(n):
        ndp = dict()
        for s in dp.values():
            # 黒いセルを追加
            nclus = [n] + s.clus[:-1]
            # nclus = [0] * n
            # for k in range(n-1):
            #     nclus[k+1] = s.clus[k]
            # nclus[0] = n
            if i > 0 and s.clus[0] != -1:
                for k in range(1, n):
                    if nclus[k] == s.clus[0]:
                        nclus[k] = n
            if s.clus[-1] != -1:
                for k in range(1, n):
                    if nclus[k] == s.clus[-1]:
                        nclus[k] = n
            normalize(nclus)
            ns = State(nclus, s.val, s.hidden)
            add(ns, ndp)

            nclus = [-1] + s.clus[:-1]
            # nclus = [0] * n
            # for k in range(n-1):
            #     nclus[k+1] = s.clus[k]
            # nclus[0] = -1
            nhidden = s.hidden
            if s.clus[-1] != -1 and all(s.clus[_] != s.clus[-1] for _ in range(n-1)):
                nhidden += 1
            numclus = nhidden + (1 if any(_ != -1 for _ in nclus) else 0)

            if numclus <= 1:
                normalize(nclus)
                ns = State(nclus, s.val, nhidden)
                add(ns, ndp)
        dp = ndp

ans = 0
for s in dp.values():
    if s.hidden == 1 and all(_ == -1 for _ in s.clus):
        ans += s.val
print(ans % MOD)
0