結果
問題 | No.1561 connect x connect |
ユーザー | uwi |
提出日時 | 2020-11-27 02:41:01 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,312 bytes |
コンパイル時間 | 88 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-06-25 07:56:00 |
合計ジャッジ時間 | 2,374 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
ソースコード
from numba import jit 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 @jit 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 @jit 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 @jit def main(): 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 = [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 = [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 if nhidden <= 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) main()