結果

問題 No.1470 Mex Sum
ユーザー yuruhiya
提出日時 2021-04-09 21:33:59
言語 Crystal
(1.14.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 12,970 ms
コンパイル使用メモリ 295,584 KB
実行使用メモリ 16,172 KB
最終ジャッジ日時 2024-06-25 04:26:11
合計ジャッジ時間 15,725 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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