結果

問題 No.2463 ストレートフラッシュ
ユーザー rlangevinrlangevin
提出日時 2023-09-08 21:58:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 79,528 KB
最終ジャッジ日時 2023-09-08 21:58:55
合計ジャッジ時間 7,199 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,420 KB
testcase_01 AC 72 ms
71,212 KB
testcase_02 AC 70 ms
71,328 KB
testcase_03 AC 82 ms
76,144 KB
testcase_04 AC 85 ms
76,604 KB
testcase_05 AC 87 ms
76,428 KB
testcase_06 AC 77 ms
75,960 KB
testcase_07 AC 80 ms
76,476 KB
testcase_08 AC 87 ms
76,620 KB
testcase_09 AC 89 ms
76,684 KB
testcase_10 AC 83 ms
76,676 KB
testcase_11 AC 76 ms
76,256 KB
testcase_12 AC 84 ms
76,624 KB
testcase_13 AC 243 ms
78,844 KB
testcase_14 AC 265 ms
78,916 KB
testcase_15 AC 258 ms
78,820 KB
testcase_16 AC 275 ms
78,956 KB
testcase_17 AC 301 ms
79,144 KB
testcase_18 AC 313 ms
79,500 KB
testcase_19 AC 323 ms
79,156 KB
testcase_20 AC 327 ms
79,416 KB
testcase_21 AC 284 ms
79,440 KB
testcase_22 AC 300 ms
79,520 KB
testcase_23 AC 301 ms
79,456 KB
testcase_24 AC 317 ms
79,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
ind = [[-1] * (N + 1) for i in range(M)]
for i in range(N * M):
    n, m = map(int, input().split())
    n, m = n - 1, m - 1
    ind[m][n] = i
    
for m in range(M):
    ind[m][-1] = ind[m][0]
   

def solve(A):
    now = -1
    card = 0
    cnt = 0
    while card != 5:
        nex = A[card]
        d = 5 - card
        n = (nex - now + d - 1)//d
        now += d * n
        cnt += n
        card = 0
        for i in range(5):
            if A[i] <= now:
                card += 1
    return cnt - 1
            
            

ans = 10 ** 18 
for m in range(M):
    for i in range(N - 3):
        L = []
        for j in range(5):
            L.append(ind[m][i + j])
        L.sort()
        ans = min(ans, solve(L))
        
print(ans)
0