結果
| 問題 |
No.2463 ストレートフラッシュ
|
| コンテスト | |
| ユーザー |
mymelochan
|
| 提出日時 | 2023-09-08 22:03:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 303 ms / 2,000 ms |
| コード長 | 1,330 bytes |
| コンパイル時間 | 434 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 105,088 KB |
| 最終ジャッジ日時 | 2024-06-26 15:02:42 |
| 合計ジャッジ時間 | 5,450 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#############################################################
import sys
sys.setrecursionlimit(10**7)
from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations
ipt = sys.stdin.readline
def iin():
return int(ipt())
def lmin():
return list(map(int,ipt().split()))
MOD = 998244353
#############################################################
N,M = lmin()
L = [lmin() for _ in range(N*M)]
idx = [[0]*N for _ in range(M)]
for i,(n,m) in enumerate(L):
idx[m-1][n-1] = i
ans = 1<<60
for i in range(M):
for j in range(N-3):
T = []
cnt = 0
tmp = 0
for k in range(5):
if idx[i][(j+k)%N] < 5:
cnt += 1
else:
T.append(idx[i][(j+k)%N])
T.sort(reverse=True)
#print(T)
cur = 4
while T:
#print(cur,cnt,tmp)
if cnt == 4:
d = T[-1]-cur
else:
d = (T[-1]-cur+5-cnt-1)//(5-cnt)
nxt = cur+d*(5-cnt)
tmp += d
while T and T[-1] <= nxt:
T.pop()
cnt += 1
cur = nxt
#print(tmp)
ans = min(ans,tmp)
#print(idx)
print(ans)
mymelochan