結果

問題 No.1345 Beautiful BINGO
ユーザー titiatitia
提出日時 2021-01-18 09:07:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,635 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 86,564 KB
実行使用メモリ 77,924 KB
最終ジャッジ日時 2023-08-20 16:21:51
合計ジャッジ時間 23,054 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,356 KB
testcase_01 AC 62 ms
71,200 KB
testcase_02 AC 56 ms
71,184 KB
testcase_03 AC 58 ms
71,420 KB
testcase_04 AC 58 ms
71,188 KB
testcase_05 AC 85 ms
76,716 KB
testcase_06 AC 58 ms
71,196 KB
testcase_07 AC 94 ms
77,504 KB
testcase_08 AC 62 ms
71,288 KB
testcase_09 AC 57 ms
71,396 KB
testcase_10 AC 65 ms
76,380 KB
testcase_11 AC 71 ms
76,564 KB
testcase_12 AC 58 ms
71,452 KB
testcase_13 AC 91 ms
77,692 KB
testcase_14 AC 59 ms
71,452 KB
testcase_15 AC 61 ms
71,560 KB
testcase_16 AC 68 ms
76,396 KB
testcase_17 AC 59 ms
71,336 KB
testcase_18 AC 58 ms
71,432 KB
testcase_19 AC 59 ms
71,380 KB
testcase_20 AC 61 ms
71,572 KB
testcase_21 AC 58 ms
71,336 KB
testcase_22 AC 66 ms
76,508 KB
testcase_23 AC 108 ms
76,388 KB
testcase_24 AC 116 ms
77,776 KB
testcase_25 AC 111 ms
77,876 KB
testcase_26 AC 354 ms
77,524 KB
testcase_27 AC 1,601 ms
77,520 KB
testcase_28 AC 103 ms
77,856 KB
testcase_29 AC 286 ms
77,336 KB
testcase_30 AC 79 ms
76,372 KB
testcase_31 AC 102 ms
77,724 KB
testcase_32 AC 94 ms
77,324 KB
testcase_33 AC 1,607 ms
77,676 KB
testcase_34 AC 78 ms
76,384 KB
testcase_35 AC 93 ms
77,924 KB
testcase_36 AC 465 ms
77,448 KB
testcase_37 AC 69 ms
76,548 KB
testcase_38 AC 279 ms
77,492 KB
testcase_39 AC 1,603 ms
77,456 KB
testcase_40 AC 528 ms
77,556 KB
testcase_41 AC 309 ms
77,388 KB
testcase_42 AC 58 ms
71,424 KB
testcase_43 AC 58 ms
71,244 KB
testcase_44 AC 59 ms
71,396 KB
testcase_45 AC 58 ms
71,132 KB
testcase_46 AC 59 ms
71,228 KB
testcase_47 AC 56 ms
71,228 KB
testcase_48 AC 57 ms
71,352 KB
testcase_49 AC 59 ms
71,364 KB
testcase_50 AC 58 ms
71,180 KB
testcase_51 AC 57 ms
71,264 KB
testcase_52 AC 114 ms
76,800 KB
testcase_53 AC 1,635 ms
77,600 KB
testcase_54 AC 257 ms
77,524 KB
testcase_55 AC 551 ms
77,876 KB
testcase_56 AC 115 ms
77,224 KB
testcase_57 AC 1,551 ms
77,428 KB
testcase_58 AC 1,034 ms
77,632 KB
testcase_59 AC 1,612 ms
77,216 KB
testcase_60 AC 709 ms
77,440 KB
testcase_61 AC 708 ms
77,852 KB
testcase_62 AC 103 ms
76,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
A=[]
for i in range(N):
    A.extend(list(map(int,input().split())))

ANS=1<<30
for i in range(1<<(N+2)):
    
    x=0
    for j in range(N+2):
        if (1<<j) & i !=0:
            x+=1

    r=M-x

    if r<0 or r>N:
        continue

    B=[0]*(N*N)

    for j in range(N+2):
        if (1<<j) & i != 0:
            if j<N:
                for k in range(N):
                    B[k*N+j]=1
            elif j==N:
                for k in range(N):
                    B[k*N+k]=1
            else:
                for k in range(N):
                    B[k*N+N-k-1]=1

    SCORE=0
    C=[]

    for j in range(N):
        sc=0
        for k in range(N):
            if B[j*N+k]==1:
                SCORE+=A[j*N+k]
            else:
                sc+=A[j*N+k]
        C.append(sc)

    C.sort()

    ANS=min(ANS,SCORE+sum(C[:r]))

print(ANS)
    
            
            

    
        
0