結果
問題 | No.506 限られたジャパリまん |
ユーザー |
![]() |
提出日時 | 2023-09-09 12:03:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 1,709 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 82,228 KB |
実行使用メモリ | 76,764 KB |
最終ジャッジ日時 | 2024-06-28 04:30:09 |
合計ジャッジ時間 | 2,393 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
import sys# sys.setrecursionlimit(200005)# sys.set_int_max_str_digits(1000005)int1 = lambda x: int(x)-1pDB = 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 = 998244353from itertools import combinationscc=[[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]=1else: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=-1ans=[]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:continuedp[dpi]-=dp[dpj]*cc[x-px+y-py][x-px]if dp[-1]>mx:mx=dp[-1]ans=iiprint(mx%md)if mx:for i in range(k):if i in ans:continueprint(friends[i])