結果
問題 | No.1345 Beautiful BINGO |
ユーザー | chineristAC |
提出日時 | 2021-01-16 13:42:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 597 ms / 2,000 ms |
コード長 | 1,502 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 83,024 KB |
最終ジャッジ日時 | 2024-05-06 06:51:16 |
合計ジャッジ時間 | 13,462 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,608 KB |
testcase_01 | AC | 39 ms
52,864 KB |
testcase_02 | AC | 37 ms
52,352 KB |
testcase_03 | AC | 38 ms
52,480 KB |
testcase_04 | AC | 38 ms
52,224 KB |
testcase_05 | AC | 46 ms
59,136 KB |
testcase_06 | AC | 38 ms
52,608 KB |
testcase_07 | AC | 89 ms
77,068 KB |
testcase_08 | AC | 37 ms
52,480 KB |
testcase_09 | AC | 37 ms
52,608 KB |
testcase_10 | AC | 39 ms
52,736 KB |
testcase_11 | AC | 51 ms
60,032 KB |
testcase_12 | AC | 37 ms
52,480 KB |
testcase_13 | AC | 90 ms
76,544 KB |
testcase_14 | AC | 44 ms
52,864 KB |
testcase_15 | AC | 42 ms
52,224 KB |
testcase_16 | AC | 44 ms
53,248 KB |
testcase_17 | AC | 42 ms
52,480 KB |
testcase_18 | AC | 41 ms
52,352 KB |
testcase_19 | AC | 42 ms
52,608 KB |
testcase_20 | AC | 42 ms
52,096 KB |
testcase_21 | AC | 43 ms
52,864 KB |
testcase_22 | AC | 179 ms
78,164 KB |
testcase_23 | AC | 388 ms
77,524 KB |
testcase_24 | AC | 253 ms
77,604 KB |
testcase_25 | AC | 137 ms
77,524 KB |
testcase_26 | AC | 280 ms
80,460 KB |
testcase_27 | AC | 442 ms
78,112 KB |
testcase_28 | AC | 170 ms
78,272 KB |
testcase_29 | AC | 205 ms
77,400 KB |
testcase_30 | AC | 157 ms
77,532 KB |
testcase_31 | AC | 171 ms
78,420 KB |
testcase_32 | AC | 117 ms
77,328 KB |
testcase_33 | AC | 421 ms
78,812 KB |
testcase_34 | AC | 121 ms
77,300 KB |
testcase_35 | AC | 123 ms
77,296 KB |
testcase_36 | AC | 543 ms
80,724 KB |
testcase_37 | AC | 131 ms
77,736 KB |
testcase_38 | AC | 296 ms
80,832 KB |
testcase_39 | AC | 458 ms
79,304 KB |
testcase_40 | AC | 297 ms
78,368 KB |
testcase_41 | AC | 438 ms
83,024 KB |
testcase_42 | AC | 36 ms
52,096 KB |
testcase_43 | AC | 37 ms
52,352 KB |
testcase_44 | AC | 36 ms
52,352 KB |
testcase_45 | AC | 37 ms
52,736 KB |
testcase_46 | AC | 36 ms
52,736 KB |
testcase_47 | AC | 36 ms
52,352 KB |
testcase_48 | AC | 37 ms
52,352 KB |
testcase_49 | AC | 36 ms
52,608 KB |
testcase_50 | AC | 37 ms
52,480 KB |
testcase_51 | AC | 36 ms
52,608 KB |
testcase_52 | AC | 471 ms
79,960 KB |
testcase_53 | AC | 454 ms
79,724 KB |
testcase_54 | AC | 408 ms
77,776 KB |
testcase_55 | AC | 443 ms
78,032 KB |
testcase_56 | AC | 496 ms
79,964 KB |
testcase_57 | AC | 453 ms
79,272 KB |
testcase_58 | AC | 431 ms
78,544 KB |
testcase_59 | AC | 439 ms
78,552 KB |
testcase_60 | AC | 597 ms
81,792 KB |
testcase_61 | AC | 454 ms
77,524 KB |
testcase_62 | AC | 416 ms
78,280 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))