結果

問題 No.769 UNOシミュレータ
ユーザー Takuya NoguchiTakuya Noguchi
提出日時 2019-02-02 22:24:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 478 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 54,892 KB
最終ジャッジ日時 2024-05-02 00:27:45
合計ジャッジ時間 5,721 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,288 KB
testcase_01 AC 75 ms
12,288 KB
testcase_02 AC 74 ms
12,288 KB
testcase_03 AC 75 ms
12,160 KB
testcase_04 AC 79 ms
12,288 KB
testcase_05 AC 81 ms
12,288 KB
testcase_06 AC 81 ms
12,416 KB
testcase_07 AC 79 ms
12,416 KB
testcase_08 AC 82 ms
12,288 KB
testcase_09 AC 94 ms
13,312 KB
testcase_10 AC 98 ms
13,184 KB
testcase_11 AC 97 ms
13,184 KB
testcase_12 AC 210 ms
27,648 KB
testcase_13 AC 206 ms
27,648 KB
testcase_14 AC 207 ms
27,520 KB
testcase_15 AC 344 ms
39,040 KB
testcase_16 AC 330 ms
38,912 KB
testcase_17 AC 357 ms
38,912 KB
testcase_18 AC 475 ms
54,752 KB
testcase_19 AC 449 ms
54,660 KB
testcase_20 AC 478 ms
54,512 KB
testcase_21 AC 444 ms
54,892 KB
testcase_22 AC 76 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
l = readlines.map(&:chomp)

card_nums, draw_card_nums = Hash.new(0), Hash.new(0)
stack_card_num, skip, increment, prev_op = 0, false, 1, nil
current_user_index = 0

loop do
  if skip
    current_user_index = (current_user_index + increment) % N
    skip = false
    next
  end

  op = l.shift

  if op != 'drawtwo' && prev_op == 'drawtwo' ||
     op != 'drawfour' && prev_op == 'drawfour'
    draw_card_nums[current_user_index] += stack_card_num
    current_user_index = (current_user_index + increment) % N
    stack_card_num = 0
  end

  case op
  when 'drawtwo', 'drawfour'
    stack_card_num += (op == 'drawtwo' ? 2 : 4)
  when 'reverse'
    increment = -increment
  when 'skip'
    skip = true
  end

  card_nums[current_user_index] += 1
  prev_op = op

  break if l.empty?

  current_user_index = (current_user_index + increment) % N
end

card_num = card_nums[current_user_index] - draw_card_nums[current_user_index]
puts "#{current_user_index + 1} #{card_num}"
0