結果

問題 No.74 貯金箱の退屈
ユーザー simansiman
提出日時 2021-06-25 06:24:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 11,400 KB
実行使用メモリ 15,384 KB
最終ジャッジ日時 2023-09-07 13:32:20
合計ジャッジ時間 4,588 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
15,256 KB
testcase_01 AC 73 ms
15,316 KB
testcase_02 AC 73 ms
15,052 KB
testcase_03 AC 73 ms
15,340 KB
testcase_04 AC 71 ms
15,100 KB
testcase_05 AC 74 ms
15,148 KB
testcase_06 AC 75 ms
15,140 KB
testcase_07 AC 76 ms
15,056 KB
testcase_08 AC 77 ms
15,056 KB
testcase_09 AC 77 ms
15,148 KB
testcase_10 AC 73 ms
15,320 KB
testcase_11 AC 71 ms
15,180 KB
testcase_12 AC 71 ms
15,096 KB
testcase_13 AC 70 ms
15,148 KB
testcase_14 AC 75 ms
15,340 KB
testcase_15 AC 72 ms
15,240 KB
testcase_16 AC 71 ms
15,092 KB
testcase_17 AC 73 ms
15,220 KB
testcase_18 AC 73 ms
15,128 KB
testcase_19 AC 71 ms
15,320 KB
testcase_20 AC 72 ms
15,096 KB
testcase_21 AC 70 ms
15,168 KB
testcase_22 AC 71 ms
15,320 KB
testcase_23 AC 69 ms
15,252 KB
testcase_24 AC 73 ms
15,136 KB
testcase_25 AC 70 ms
15,384 KB
testcase_26 AC 72 ms
15,160 KB
testcase_27 AC 69 ms
15,360 KB
testcase_28 AC 72 ms
15,060 KB
testcase_29 AC 73 ms
15,092 KB
testcase_30 AC 73 ms
15,360 KB
testcase_31 AC 72 ms
15,052 KB
testcase_32 AC 70 ms
15,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
D = gets.split.map(&:to_i)
W = gets.split.map(&:to_i)

E = Hash.new { |h, k| h[k] = {} }
O = Hash.new(false)

D.each_with_index do |d, i|
  u = (i + d) % N
  v = (i - d) % N

  O[u] = true if u == v
  E[u][v] = true
  E[v][u] = true
end

visited = Hash.new(false)
all_ok = true

N.times do |u|
  next if visited[u]

  queue = []
  queue << u
  ura_cnt = 0
  one = false

  until queue.empty?
    u = queue.shift

    next if visited[u]
    visited[u] = true
    ura_cnt += 1 if W[u] == 0
    one = true if O[u]

    E[u].each_key do |v|
      queue << v
    end
  end

  if ura_cnt.odd? && !one
    all_ok = false
  end
end

if all_ok
  puts 'Yes'
else
  puts 'No'
end
0