結果

問題 No.769 UNOシミュレータ
ユーザー Takuya NoguchiTakuya Noguchi
提出日時 2019-01-31 19:39:12
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 972 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 54,524 KB
最終ジャッジ日時 2024-05-02 00:25:48
合計ジャッジ時間 7,694 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 75 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
cards = Hash.new(0)
current_user_index = 0
increment = 1
ops = readlines.map(&:chomp)
op = ops.shift
prev_op = nil
stack_cards = 0

loop do
  break if ops.empty?

  if op != 'drawtwo' && prev_op == 'drawtwo' ||
     op != 'drawfour' && prev_op == 'drawfour'
    cards[current_user_index] -= stack_cards
    stack_cards, prev_op = 0, nil
    current_user_index += increment
    current_user_index = current_user_index % N
    next
  end

  cards[current_user_index] += 1
  puts "#{current_user_index + 1} #{op}"

  if op == 'skip'
    current_user_index += increment * 2
  elsif op == 'reverse'
    increment = -increment
    current_user_index += increment
  else
    stack_cards += 2 if op == 'drawtwo'
    stack_cards += 4 if op == 'drawfour'

    current_user_index += increment
  end
  current_user_index = current_user_index % N

  prev_op = op
  op = ops.shift
end

puts [current_user_index + 1, cards[current_user_index] + 1].join(' ')
0