結果
問題 |
No.506 限られたジャパリまん
|
ユーザー |
![]() |
提出日時 | 2023-09-09 11:54:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,690 bytes |
コンパイル時間 | 248 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 76,416 KB |
最終ジャッジ日時 | 2024-06-28 04:30:06 |
合計ジャッジ時間 | 2,450 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 1 |
ソースコード
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])