結果

問題 No.1345 Beautiful BINGO
ユーザー yuruhiyayuruhiya
提出日時 2021-01-16 14:56:41
言語 Crystal
(1.11.2)
結果
AC  
実行時間 683 ms / 2,000 ms
コード長 669 bytes
コンパイル時間 18,873 ms
コンパイル使用メモリ 260,712 KB
実行使用メモリ 35,552 KB
最終ジャッジ日時 2023-09-13 13:05:30
合計ジャッジ時間 30,792 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,464 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,436 KB
testcase_03 AC 2 ms
4,420 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,588 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 4 ms
4,820 KB
testcase_08 AC 2 ms
4,424 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,540 KB
testcase_11 AC 2 ms
4,580 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,664 KB
testcase_14 AC 2 ms
4,472 KB
testcase_15 AC 2 ms
4,412 KB
testcase_16 AC 2 ms
4,388 KB
testcase_17 AC 3 ms
4,436 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,404 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,440 KB
testcase_22 AC 5 ms
5,568 KB
testcase_23 AC 53 ms
26,956 KB
testcase_24 AC 32 ms
15,096 KB
testcase_25 AC 15 ms
5,728 KB
testcase_26 AC 142 ms
12,392 KB
testcase_27 AC 662 ms
35,420 KB
testcase_28 AC 6 ms
5,292 KB
testcase_29 AC 140 ms
12,436 KB
testcase_30 AC 8 ms
6,716 KB
testcase_31 AC 8 ms
5,928 KB
testcase_32 AC 5 ms
4,852 KB
testcase_33 AC 675 ms
35,352 KB
testcase_34 AC 4 ms
4,680 KB
testcase_35 AC 4 ms
4,784 KB
testcase_36 AC 494 ms
35,460 KB
testcase_37 AC 6 ms
4,984 KB
testcase_38 AC 129 ms
12,396 KB
testcase_39 AC 683 ms
35,348 KB
testcase_40 AC 306 ms
20,164 KB
testcase_41 AC 238 ms
20,164 KB
testcase_42 AC 2 ms
4,484 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,504 KB
testcase_46 AC 3 ms
4,396 KB
testcase_47 AC 2 ms
4,496 KB
testcase_48 AC 2 ms
4,400 KB
testcase_49 AC 2 ms
4,444 KB
testcase_50 AC 3 ms
4,492 KB
testcase_51 AC 2 ms
4,432 KB
testcase_52 AC 467 ms
35,552 KB
testcase_53 AC 677 ms
35,524 KB
testcase_54 AC 126 ms
35,348 KB
testcase_55 AC 307 ms
35,408 KB
testcase_56 AC 468 ms
35,408 KB
testcase_57 AC 656 ms
35,516 KB
testcase_58 AC 658 ms
35,456 KB
testcase_59 AC 673 ms
35,416 KB
testcase_60 AC 522 ms
35,500 KB
testcase_61 AC 420 ms
35,476 KB
testcase_62 AC 468 ms
35,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

n, m = read_line.split.map(&.to_i)
a = (1..n).map { read_line.split.map(&.to_i) }
puts [false, true].repeated_permutations(n + 2).min_of { |flag|
  cnt = flag.count(true)
  if cnt + n < m
    10**9
  else
    b = [0] * n
    sum = 0
    (0...n).each { |i|
      (0...n).each { |j|
        if flag[i] || (flag[-2] && i == j) || (flag[-1] && i == (n - 1 - j))
          sum += a[i][j]
        else
          b[j] += a[i][j]
        end
      }
    }
    if cnt >= m
      sum
    else
      sum + b.sort[0, m - cnt].sum
    end
  end
}
0