結果

問題 No.1470 Mex Sum
ユーザー maguroflymagurofly
提出日時 2021-04-09 21:45:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,572 KB
実行使用メモリ 37,244 KB
最終ジャッジ日時 2023-09-07 10:40:35
合計ジャッジ時間 12,641 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,160 KB
testcase_01 AC 80 ms
15,092 KB
testcase_02 AC 101 ms
17,236 KB
testcase_03 AC 99 ms
16,856 KB
testcase_04 AC 99 ms
17,168 KB
testcase_05 AC 100 ms
17,032 KB
testcase_06 AC 99 ms
17,320 KB
testcase_07 AC 98 ms
17,296 KB
testcase_08 AC 100 ms
17,260 KB
testcase_09 AC 101 ms
17,140 KB
testcase_10 AC 99 ms
17,172 KB
testcase_11 AC 98 ms
17,124 KB
testcase_12 AC 238 ms
36,696 KB
testcase_13 AC 236 ms
36,364 KB
testcase_14 AC 237 ms
36,452 KB
testcase_15 AC 241 ms
36,916 KB
testcase_16 AC 237 ms
36,200 KB
testcase_17 AC 234 ms
36,008 KB
testcase_18 AC 235 ms
36,056 KB
testcase_19 AC 236 ms
36,060 KB
testcase_20 AC 237 ms
36,252 KB
testcase_21 AC 242 ms
36,972 KB
testcase_22 AC 241 ms
37,156 KB
testcase_23 AC 242 ms
36,952 KB
testcase_24 AC 240 ms
37,044 KB
testcase_25 AC 246 ms
37,084 KB
testcase_26 AC 240 ms
37,200 KB
testcase_27 AC 246 ms
37,092 KB
testcase_28 AC 238 ms
36,956 KB
testcase_29 AC 242 ms
37,028 KB
testcase_30 AC 241 ms
36,856 KB
testcase_31 AC 241 ms
37,164 KB
testcase_32 AC 241 ms
37,244 KB
testcase_33 AC 242 ms
37,112 KB
testcase_34 AC 241 ms
37,188 KB
testcase_35 AC 239 ms
36,928 KB
testcase_36 AC 239 ms
37,140 KB
testcase_37 AC 231 ms
36,664 KB
testcase_38 AC 235 ms
36,576 KB
testcase_39 AC 229 ms
36,652 KB
testcase_40 AC 234 ms
36,744 KB
testcase_41 AC 239 ms
36,932 KB
testcase_42 AC 238 ms
36,800 KB
testcase_43 AC 238 ms
36,740 KB
testcase_44 AC 238 ms
36,828 KB
testcase_45 AC 238 ms
36,748 KB
testcase_46 AC 234 ms
36,788 KB
testcase_47 AC 235 ms
36,832 KB
testcase_48 AC 236 ms
36,828 KB
testcase_49 AC 236 ms
36,800 KB
testcase_50 AC 234 ms
36,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Range
    def upper_bound
        ac, wa = self.begin, self.end
        wa += 1 unless self.exclude_end?
        while ac + 1 < wa
            wj = (ac + wa) / 2
            if yield(wj)
                ac = wj
            else
                wa = wj
            end
        end
        ac
    end
end

N = gets.to_i
A = gets.split.map(&:to_i)

counts = [[0, 0]]
A.each do |x|
    a, b = counts[-1]
    case x
    when 1
        counts << [a + 1, b]
    when 2
        counts << [a, b + 1]
    else
        counts << [a, b]
    end
end

ans = 0
(0 .. N - 2).each do |l|
    ones = counts[N][0] - counts[l][0]
    twos = counts[N][1] - counts[l][1]
    others = N - l - ones - twos - 1
    case A[l]
    when 1
        ans += (ones + others) * 2 + twos * 3
    when 2
        ans += (twos + others) * 1 + ones * 3
    else
        ans += (twos + others) * 1 + ones * 2
    end
end

puts ans
0