結果

問題 No.2463 ストレートフラッシュ
ユーザー titiatitia
提出日時 2023-09-17 01:26:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 731 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 129,984 KB
最終ジャッジ日時 2023-09-17 01:26:42
合計ジャッジ時間 11,077 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,224 KB
testcase_01 AC 61 ms
71,216 KB
testcase_02 AC 61 ms
71,260 KB
testcase_03 AC 72 ms
76,572 KB
testcase_04 AC 104 ms
76,704 KB
testcase_05 AC 81 ms
76,568 KB
testcase_06 AC 61 ms
71,392 KB
testcase_07 AC 75 ms
76,440 KB
testcase_08 AC 80 ms
76,932 KB
testcase_09 AC 85 ms
77,800 KB
testcase_10 AC 82 ms
76,980 KB
testcase_11 AC 64 ms
75,976 KB
testcase_12 AC 80 ms
76,756 KB
testcase_13 AC 516 ms
111,200 KB
testcase_14 AC 562 ms
121,476 KB
testcase_15 AC 581 ms
116,224 KB
testcase_16 AC 571 ms
121,824 KB
testcase_17 AC 672 ms
125,228 KB
testcase_18 AC 698 ms
129,884 KB
testcase_19 AC 731 ms
129,892 KB
testcase_20 AC 704 ms
129,892 KB
testcase_21 AC 703 ms
129,896 KB
testcase_22 AC 692 ms
129,984 KB
testcase_23 AC 700 ms
129,804 KB
testcase_24 AC 649 ms
129,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    
0