結果

問題 No.1765 While Shining
ユーザー tamura2004
提出日時 2022-02-12 21:29:14
言語 Crystal
(1.14.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 311 bytes
コンパイル時間 11,666 ms
コンパイル使用メモリ 297,948 KB
実行使用メモリ 12,780 KB
最終ジャッジ日時 2024-06-29 00:26:11
合計ジャッジ時間 13,453 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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