結果
問題 | No.1345 Beautiful BINGO |
ユーザー | chineristAC |
提出日時 | 2021-01-16 13:42:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 619 ms / 2,000 ms |
コード長 | 1,502 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 83,024 KB |
最終ジャッジ日時 | 2024-11-28 11:51:13 |
合計ジャッジ時間 | 14,441 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,224 KB |
testcase_01 | AC | 43 ms
52,608 KB |
testcase_02 | AC | 37 ms
52,736 KB |
testcase_03 | AC | 38 ms
52,224 KB |
testcase_04 | AC | 37 ms
52,224 KB |
testcase_05 | AC | 43 ms
59,008 KB |
testcase_06 | AC | 37 ms
52,352 KB |
testcase_07 | AC | 84 ms
75,904 KB |
testcase_08 | AC | 37 ms
51,712 KB |
testcase_09 | AC | 37 ms
52,480 KB |
testcase_10 | AC | 38 ms
52,480 KB |
testcase_11 | AC | 45 ms
60,160 KB |
testcase_12 | AC | 43 ms
52,608 KB |
testcase_13 | AC | 84 ms
76,288 KB |
testcase_14 | AC | 39 ms
52,736 KB |
testcase_15 | AC | 38 ms
52,352 KB |
testcase_16 | AC | 40 ms
52,480 KB |
testcase_17 | AC | 39 ms
52,992 KB |
testcase_18 | AC | 39 ms
52,224 KB |
testcase_19 | AC | 39 ms
52,352 KB |
testcase_20 | AC | 37 ms
52,224 KB |
testcase_21 | AC | 39 ms
52,608 KB |
testcase_22 | AC | 170 ms
77,908 KB |
testcase_23 | AC | 427 ms
76,880 KB |
testcase_24 | AC | 281 ms
77,520 KB |
testcase_25 | AC | 140 ms
77,008 KB |
testcase_26 | AC | 293 ms
79,812 KB |
testcase_27 | AC | 451 ms
78,304 KB |
testcase_28 | AC | 155 ms
77,888 KB |
testcase_29 | AC | 195 ms
77,156 KB |
testcase_30 | AC | 162 ms
76,876 KB |
testcase_31 | AC | 182 ms
78,040 KB |
testcase_32 | AC | 111 ms
76,620 KB |
testcase_33 | AC | 471 ms
77,776 KB |
testcase_34 | AC | 123 ms
76,792 KB |
testcase_35 | AC | 131 ms
77,040 KB |
testcase_36 | AC | 610 ms
80,208 KB |
testcase_37 | AC | 131 ms
77,476 KB |
testcase_38 | AC | 327 ms
80,956 KB |
testcase_39 | AC | 501 ms
79,064 KB |
testcase_40 | AC | 350 ms
78,636 KB |
testcase_41 | AC | 486 ms
83,024 KB |
testcase_42 | AC | 38 ms
52,096 KB |
testcase_43 | AC | 37 ms
52,352 KB |
testcase_44 | AC | 39 ms
52,608 KB |
testcase_45 | AC | 38 ms
53,120 KB |
testcase_46 | AC | 37 ms
51,712 KB |
testcase_47 | AC | 38 ms
52,480 KB |
testcase_48 | AC | 38 ms
52,352 KB |
testcase_49 | AC | 38 ms
52,096 KB |
testcase_50 | AC | 39 ms
52,864 KB |
testcase_51 | AC | 38 ms
52,608 KB |
testcase_52 | AC | 523 ms
79,620 KB |
testcase_53 | AC | 491 ms
79,584 KB |
testcase_54 | AC | 442 ms
77,564 KB |
testcase_55 | AC | 454 ms
77,268 KB |
testcase_56 | AC | 516 ms
79,572 KB |
testcase_57 | AC | 511 ms
78,644 KB |
testcase_58 | AC | 464 ms
78,036 KB |
testcase_59 | AC | 461 ms
77,916 KB |
testcase_60 | AC | 619 ms
81,204 KB |
testcase_61 | AC | 465 ms
77,268 KB |
testcase_62 | AC | 444 ms
78,288 KB |
ソースコード
N,M = map(int,input().split()) A = [list(map(int,input().split())) for i in range(N)] S = [sum(A[j][i] for j in range(N)) for i in range(N)] tmp_A = [[A[i][j] for j in range(N)] for i in range(N)] tmp_S = [S[i] for i in range(N)] def dfs(i,cost,cnt): res = 10**18 if i==N+2: column = [tmp_S[j] for j in range(N)] column.sort() cost += sum(column[:cnt]) return cost elif i<N: tmp1 = dfs(i+1,cost,cnt) for j in range(N): tmp_A[i][j] = 0 cost += A[i][j] tmp_S[j] -= A[i][j] tmp2 = dfs(i+1,cost,cnt-1) for j in range(N): tmp_A[i][j] = A[i][j] tmp_S[j] += A[i][j] return min(res,tmp1,tmp2) elif i==N: tmp1 = dfs(i+1,cost,cnt) memo = [tmp_A[j][j] for j in range(N)] for j in range(N): tmp_A[j][j] = 0 cost += memo[j] tmp_S[j] -= memo[j] tmp2 = dfs(i+1,cost,cnt-1) for j in range(N): tmp_A[j][j] = memo[j] tmp_S[j] += memo[j] return min(res,tmp1,tmp2) else: tmp1 = dfs(i+1,cost,cnt) memo = [tmp_A[N-1-j][j] for j in range(N)] for j in range(N): tmp_A[N-1-j][j] = 0 cost += memo[j] tmp_S[j] -= memo[j] tmp2 = dfs(i+1,cost,cnt-1) for j in range(N): tmp_A[N-1-j][j] = memo[j] tmp_S[j] += memo[j] return min(res,tmp1,tmp2) print(dfs(0,0,M))