結果

問題 No.506 限られたジャパリまん
ユーザー mkawa2mkawa2
提出日時 2023-09-09 12:03:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,709 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 77,296 KB
最終ジャッジ日時 2023-09-10 12:59:04
合計ジャッジ時間 3,550 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,392 KB
testcase_01 AC 77 ms
75,472 KB
testcase_02 AC 76 ms
75,336 KB
testcase_03 AC 77 ms
75,268 KB
testcase_04 AC 77 ms
75,436 KB
testcase_05 AC 77 ms
75,356 KB
testcase_06 AC 76 ms
75,540 KB
testcase_07 AC 77 ms
75,336 KB
testcase_08 AC 115 ms
77,296 KB
testcase_09 AC 118 ms
77,276 KB
testcase_10 AC 91 ms
76,124 KB
testcase_11 AC 109 ms
76,960 KB
testcase_12 AC 107 ms
76,936 KB
testcase_13 AC 78 ms
75,492 KB
testcase_14 AC 77 ms
75,788 KB
testcase_15 AC 78 ms
75,500 KB
testcase_16 AC 114 ms
77,080 KB
testcase_17 AC 78 ms
75,488 KB
testcase_18 AC 79 ms
75,508 KB
testcase_19 AC 102 ms
76,672 KB
testcase_20 AC 91 ms
76,480 KB
testcase_21 AC 77 ms
75,380 KB
testcase_22 AC 95 ms
76,204 KB
testcase_23 AC 88 ms
76,328 KB
testcase_24 AC 91 ms
76,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(1000005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = -1-(-1 << 63)
md = 10**9+7
# md = 998244353

from itertools import combinations

cc=[[0]*70 for _ in range(70)]
for i in range(1,65):
    for j in range(i+1):
        if j==0 or i==j:
            cc[i][j]=1
        else:
            cc[i][j]=cc[i-1][j]+cc[i-1][j-1]

h,w,k,p=LI()
xy=[]
friends=[]
for _ in range(k):
    x,y,f=SI().split()
    x,y=int(x),int(y)
    xy.append((x,y))
    friends.append(f)
xy.append((h,w))

if k==p:
    print(cc[h+w][h]%md)
    for f in friends:print(f)
    exit()

mx=-1
ans=[]
for ii in combinations(range(k),k-p):
    si=sorted(ii,key=lambda i:xy[i][0]+xy[i][1])+[-1]
    dp=[0]*(k-p+1)
    for dpi,xyi in enumerate(si):
        x,y=xy[xyi]
        dp[dpi]=cc[x+y][x]
        for dpj,xyj in enumerate(si[:dpi]):
            px,py=xy[xyj]
            if px>x or py>y:continue
            dp[dpi]-=dp[dpj]*cc[x-px+y-py][x-px]
    if dp[-1]>mx:
        mx=dp[-1]
        ans=ii

print(mx%md)
if mx:
    for i in range(k):
        if i in ans:continue
        print(friends[i])
0