結果
問題 |
No.2463 ストレートフラッシュ
|
ユーザー |
![]() |
提出日時 | 2023-09-17 01:26:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 842 ms / 2,000 ms |
コード長 | 1,144 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 81,648 KB |
実行使用メモリ | 129,832 KB |
最終ジャッジ日時 | 2024-07-03 23:39:17 |
合計ジャッジ時間 | 11,984 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import sys input = sys.stdin.readline N,M=map(int,input().split()) CARD=[tuple(map(int,input().split())) for i in range(N*M)] D=dict() for i in range(N*M): D[CARD[i]]=i def calc(L): #print("!",L) ANS=0 count=5 while count>0: #print(L) if L[0]>=count: x=L[0]//count ANS+=x for i in range(len(L)): L[i]-=x*count c=0 while L: if L[0]<count: L.pop(0) c+=1 continue for j in range(len(L)): L[j]-=count break if L==[]: break ANS+=1 count-=c #print(ANS) return ANS ANS=1<<63 for i in range(1,M+1): for j in range(5,N+1): LIST=[] for k in range(j-4,j+1): LIST.append(D[(k,i)]) #print(sorted(LIST)) ANS=min(ANS,calc(sorted(LIST))) LIST=[] for k in range(N-3,N+1): LIST.append(D[(k,i)]) LIST.append(D[(1,i)]) #print(sorted(LIST)) ANS=min(ANS,calc(sorted(LIST))) print(ANS)