結果

問題 No.506 限られたジャパリまん
ユーザー mkawa2mkawa2
提出日時 2023-09-09 11:54:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,690 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 77,744 KB
最終ジャッジ日時 2023-09-10 12:59:02
合計ジャッジ時間 3,632 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,764 KB
testcase_01 AC 77 ms
75,880 KB
testcase_02 AC 81 ms
75,952 KB
testcase_03 AC 78 ms
76,136 KB
testcase_04 AC 78 ms
75,936 KB
testcase_05 AC 77 ms
75,880 KB
testcase_06 AC 79 ms
75,936 KB
testcase_07 AC 78 ms
75,832 KB
testcase_08 AC 115 ms
77,488 KB
testcase_09 AC 117 ms
77,744 KB
testcase_10 AC 91 ms
76,636 KB
testcase_11 AC 109 ms
77,500 KB
testcase_12 AC 106 ms
77,364 KB
testcase_13 AC 77 ms
75,860 KB
testcase_14 AC 78 ms
75,924 KB
testcase_15 AC 79 ms
75,908 KB
testcase_16 AC 115 ms
77,540 KB
testcase_17 AC 78 ms
75,948 KB
testcase_18 AC 76 ms
75,824 KB
testcase_19 AC 102 ms
77,300 KB
testcase_20 AC 91 ms
76,788 KB
testcase_21 AC 78 ms
75,876 KB
testcase_22 AC 93 ms
77,020 KB
testcase_23 AC 88 ms
76,616 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
for i in range(k):
    if i in ans:continue
    print(friends[i])
0