結果

問題 No.2463 ストレートフラッシュ
ユーザー 👑 KazunKazun
提出日時 2021-05-25 00:32:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 86,784 KB
実行使用メモリ 79,800 KB
最終ジャッジ日時 2023-09-08 14:57:40
合計ジャッジ時間 6,390 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,400 KB
testcase_01 AC 72 ms
71,328 KB
testcase_02 AC 73 ms
71,456 KB
testcase_03 AC 78 ms
71,368 KB
testcase_04 AC 87 ms
76,184 KB
testcase_05 AC 89 ms
75,996 KB
testcase_06 AC 72 ms
71,452 KB
testcase_07 AC 81 ms
75,628 KB
testcase_08 AC 86 ms
75,464 KB
testcase_09 AC 108 ms
77,452 KB
testcase_10 AC 84 ms
75,424 KB
testcase_11 AC 74 ms
71,180 KB
testcase_12 AC 91 ms
75,948 KB
testcase_13 AC 250 ms
79,268 KB
testcase_14 AC 263 ms
79,268 KB
testcase_15 AC 255 ms
79,268 KB
testcase_16 AC 262 ms
79,072 KB
testcase_17 AC 300 ms
79,696 KB
testcase_18 AC 318 ms
79,700 KB
testcase_19 AC 315 ms
79,724 KB
testcase_20 AC 310 ms
79,800 KB
testcase_21 AC 288 ms
79,440 KB
testcase_22 AC 285 ms
79,752 KB
testcase_23 AC 301 ms
79,672 KB
testcase_24 AC 318 ms
79,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def r(Y):
    Y.sort()

    a=0; i=0
    t=0
    while True:
        b=Y[i]
        j=5-i

        u=((b-a)+(j-1))//j
        t+=u
        c=a+j*u

        if i==4:
            return t

        while True:
            if Y[i+1]<=c:
                i+=1
                if i==4:
                    break
            else:
                break

        if i==4:
            return t
        else:
            a=c
            i+=1

N,M=map(int,input().split())

#カードの位置を記録
Index=[[-1]*N for _ in range(M)]
for i in range(1,N*M+1):
    n,m=map(int,input().split())
    Index[m-1][n-1]=i

#全探索
X=float("inf")
for y in range(M):
    # x, x+1, x+2, x+3, x+4 タイプを処理
    for x in range(N-4):
        X=min(X,r(Index[y][x:x+5]))

    # x-3, x-2, x-1, x, 1 タイプを処理
    X=min(X,r([Index[y][0]]+Index[y][-4:]))

print(X-1)
0