結果

問題 No.1765 While Shining
ユーザー maguroflymagurofly
提出日時 2021-11-26 22:30:06
言語 Ruby
(3.3.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 201 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 11,180 KB
実行使用メモリ 30,356 KB
最終ジャッジ日時 2023-09-12 05:10:22
合計ジャッジ時間 5,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,096 KB
testcase_01 AC 84 ms
15,228 KB
testcase_02 AC 84 ms
15,216 KB
testcase_03 AC 85 ms
15,112 KB
testcase_04 AC 86 ms
15,020 KB
testcase_05 AC 86 ms
15,052 KB
testcase_06 AC 84 ms
15,196 KB
testcase_07 AC 85 ms
15,228 KB
testcase_08 AC 86 ms
15,112 KB
testcase_09 AC 168 ms
24,988 KB
testcase_10 AC 203 ms
29,120 KB
testcase_11 AC 192 ms
27,696 KB
testcase_12 AC 199 ms
28,396 KB
testcase_13 AC 186 ms
27,196 KB
testcase_14 AC 210 ms
30,156 KB
testcase_15 AC 211 ms
30,136 KB
testcase_16 AC 211 ms
30,356 KB
testcase_17 AC 210 ms
30,228 KB
testcase_18 AC 213 ms
30,152 KB
testcase_19 AC 215 ms
30,192 KB
testcase_20 AC 212 ms
30,160 KB
testcase_21 AC 211 ms
30,144 KB
testcase_22 AC 212 ms
30,208 KB
testcase_23 AC 213 ms
30,244 KB
testcase_24 AC 213 ms
30,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

dp = [1] * N
dp[N - 1] = 0
(0 ... N - 1).reverse_each do |i|
    dp[i] = dp[i + 1] + 1 if A[i + 1] ^ 1 == A[i]
end

puts (0 ... N - 1).sum { |i| A[i] * dp[i] }
0