結果

問題 No.2463 ストレートフラッシュ
ユーザー miya145592miya145592
提出日時 2023-09-08 23:41:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 106,400 KB
最終ジャッジ日時 2023-09-08 23:41:45
合計ジャッジ時間 7,769 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,504 KB
testcase_01 AC 67 ms
71,248 KB
testcase_02 AC 68 ms
71,244 KB
testcase_03 AC 87 ms
76,668 KB
testcase_04 AC 105 ms
77,756 KB
testcase_05 AC 110 ms
77,800 KB
testcase_06 AC 69 ms
71,252 KB
testcase_07 AC 85 ms
76,736 KB
testcase_08 AC 104 ms
77,764 KB
testcase_09 AC 123 ms
78,212 KB
testcase_10 AC 91 ms
76,516 KB
testcase_11 AC 71 ms
71,352 KB
testcase_12 AC 105 ms
77,572 KB
testcase_13 AC 336 ms
97,848 KB
testcase_14 AC 355 ms
99,916 KB
testcase_15 AC 356 ms
99,668 KB
testcase_16 AC 362 ms
100,520 KB
testcase_17 AC 430 ms
104,420 KB
testcase_18 AC 428 ms
106,108 KB
testcase_19 AC 447 ms
106,256 KB
testcase_20 AC 421 ms
106,128 KB
testcase_21 AC 404 ms
106,364 KB
testcase_22 AC 441 ms
106,260 KB
testcase_23 AC 406 ms
106,252 KB
testcase_24 AC 422 ms
106,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
NM = [list(map(int, input().split())) for _ in range(N*M)]
dp = [[0 for _ in range(N+1)] for _ in range(M)]
for i in range(5):
    n, m = NM[i]
    n-=1
    m-=1
    dp[m][n] = 1
    if n==0:
        dp[m][N] = 1
cnt = 1
for i in range(5, N*M):
    n, m = NM[i]
    n-=1
    m-=1
    dp[m][n] = cnt+1
    if n==0:
        dp[m][N] = cnt+1
    cnt+=1
#print(dp)
INF = N*M
ans = INF
for i in range(M):
    for j in range(N):
        S = []
        flag = True
        for k in range(j, j+5):
            if 0<=k<=N:
                S.append(dp[i][k])
            else:
                flag = False
                break
        if flag:
            S.sort()
            tmp = 0
            st = 1
            a = S.count(st)
            while S[-1]>st:
                tmp2 = (S[a]-st)//(5-a) + (1 if (S[a]-st)%(5-a) else 0)
                tmp+=tmp2
                st+=(5-a)* tmp2
                for idx in range(a, 5):
                    if S[idx]>st:
                        a = idx
                        break
            #print(S, tmp)
            ans = min(ans, tmp)
print(ans)



0