結果

問題 No.1765 While Shining
ユーザー tamura2004tamura2004
提出日時 2022-02-12 21:29:14
言語 Crystal
(1.11.2)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 311 bytes
コンパイル時間 22,128 ms
コンパイル使用メモリ 258,308 KB
実行使用メモリ 14,940 KB
最終ジャッジ日時 2023-09-11 09:49:05
合計ジャッジ時間 24,357 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,356 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,492 KB
testcase_03 AC 3 ms
4,428 KB
testcase_04 AC 2 ms
4,556 KB
testcase_05 AC 2 ms
4,564 KB
testcase_06 AC 2 ms
4,604 KB
testcase_07 AC 3 ms
4,576 KB
testcase_08 AC 3 ms
4,588 KB
testcase_09 AC 16 ms
10,272 KB
testcase_10 AC 19 ms
11,168 KB
testcase_11 AC 18 ms
11,096 KB
testcase_12 AC 19 ms
11,152 KB
testcase_13 AC 19 ms
11,096 KB
testcase_14 AC 24 ms
14,776 KB
testcase_15 AC 24 ms
14,656 KB
testcase_16 AC 22 ms
14,740 KB
testcase_17 AC 24 ms
14,900 KB
testcase_18 AC 24 ms
14,832 KB
testcase_19 AC 24 ms
14,832 KB
testcase_20 AC 23 ms
14,792 KB
testcase_21 AC 24 ms
14,784 KB
testcase_22 AC 23 ms
14,940 KB
testcase_23 AC 23 ms
14,916 KB
testcase_24 AC 20 ms
14,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = gets.to_s.to_i
a = gets.to_s.split.map(&.to_i)

b = (0...n).map do |i|
  a[i] ^ (i % 2)
end

c = Array.new(n, 1_i64)
c[-1] = 0_i64
(1...n).reverse_each do |i|
  if b[i] == b[i-1]
    c[i-1] = c[i] + 1
  end
end

ans = 0_i64
n.times do |i|
  next if a[i] == 0
  next if i == n - 1
  ans += c[i]
end

pp ans

0