結果

問題 No.1470 Mex Sum
ユーザー yuruhiyayuruhiya
提出日時 2021-04-09 21:33:59
言語 Crystal
(1.11.2)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 24,572 ms
コンパイル使用メモリ 253,472 KB
実行使用メモリ 16,732 KB
最終ジャッジ日時 2023-09-07 10:10:39
合計ジャッジ時間 22,721 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,384 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 5 ms
5,512 KB
testcase_03 AC 5 ms
5,548 KB
testcase_04 AC 5 ms
5,576 KB
testcase_05 AC 5 ms
5,620 KB
testcase_06 AC 5 ms
5,424 KB
testcase_07 AC 5 ms
5,468 KB
testcase_08 AC 5 ms
5,552 KB
testcase_09 AC 5 ms
5,612 KB
testcase_10 AC 5 ms
5,608 KB
testcase_11 AC 5 ms
5,544 KB
testcase_12 AC 27 ms
16,456 KB
testcase_13 AC 26 ms
14,584 KB
testcase_14 AC 25 ms
14,492 KB
testcase_15 AC 28 ms
16,436 KB
testcase_16 AC 27 ms
14,768 KB
testcase_17 AC 26 ms
14,728 KB
testcase_18 AC 27 ms
14,880 KB
testcase_19 AC 27 ms
14,432 KB
testcase_20 AC 27 ms
16,120 KB
testcase_21 AC 27 ms
16,448 KB
testcase_22 AC 29 ms
16,620 KB
testcase_23 AC 28 ms
16,600 KB
testcase_24 AC 27 ms
16,520 KB
testcase_25 AC 28 ms
16,620 KB
testcase_26 AC 27 ms
16,432 KB
testcase_27 AC 29 ms
16,732 KB
testcase_28 AC 28 ms
16,564 KB
testcase_29 AC 29 ms
16,536 KB
testcase_30 AC 28 ms
16,484 KB
testcase_31 AC 28 ms
16,620 KB
testcase_32 AC 28 ms
16,476 KB
testcase_33 AC 27 ms
16,540 KB
testcase_34 AC 28 ms
16,560 KB
testcase_35 AC 29 ms
16,612 KB
testcase_36 AC 28 ms
16,596 KB
testcase_37 AC 22 ms
14,640 KB
testcase_38 AC 23 ms
14,796 KB
testcase_39 AC 21 ms
14,684 KB
testcase_40 AC 24 ms
14,684 KB
testcase_41 AC 24 ms
14,728 KB
testcase_42 AC 23 ms
14,768 KB
testcase_43 AC 23 ms
14,864 KB
testcase_44 AC 23 ms
14,868 KB
testcase_45 AC 24 ms
14,684 KB
testcase_46 AC 23 ms
14,984 KB
testcase_47 AC 22 ms
14,840 KB
testcase_48 AC 25 ms
14,764 KB
testcase_49 AC 23 ms
14,812 KB
testcase_50 AC 23 ms
14,916 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 = read_line.to_i
a = read_line.split.map(&.to_i64)
c1, c2 = {1, 2}.map { |k|
  cnt = [0] * -~n
  n.times { |i| cnt[i + 1] = cnt[i] + (a[i] == k ? 1 : 0) }
  cnt
}
puts (0...n).sum { |i|
  case a[i]
  when 1
    3i64 * c2[i] + 2i64 * (i - c2[i])
  when 2
    3i64 * c1[i] + 1i64 * (i - c1[i])
  else
    2i64 * c1[i] + 1i64 * (i - c1[i])
  end
}
0