結果

問題 No.769 UNOシミュレータ
ユーザー yuruhiyayuruhiya
提出日時 2020-07-30 11:46:03
言語 Crystal
(1.11.2)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,116 bytes
コンパイル時間 18,830 ms
コンパイル使用メモリ 253,964 KB
実行使用メモリ 5,372 KB
最終ジャッジ日時 2023-09-13 11:33:11
合計ジャッジ時間 19,922 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,420 KB
testcase_05 AC 3 ms
4,396 KB
testcase_06 AC 3 ms
4,464 KB
testcase_07 AC 2 ms
4,440 KB
testcase_08 AC 3 ms
4,392 KB
testcase_09 AC 5 ms
4,968 KB
testcase_10 AC 4 ms
4,868 KB
testcase_11 AC 4 ms
4,844 KB
testcase_12 AC 18 ms
5,116 KB
testcase_13 AC 17 ms
5,196 KB
testcase_14 AC 19 ms
5,124 KB
testcase_15 AC 32 ms
5,152 KB
testcase_16 AC 32 ms
5,108 KB
testcase_17 AC 33 ms
5,124 KB
testcase_18 AC 46 ms
5,372 KB
testcase_19 AC 47 ms
5,204 KB
testcase_20 AC 47 ms
5,260 KB
testcase_21 AC 48 ms
5,304 KB
testcase_22 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = read_line.split.map &.to_i
index, reverse = 0, 1
draw_kind, draw_count = -1, 0
count = [0] * n

m.times do |time|
  l = read_line
  if draw_kind != -1 && [l, draw_kind] != ["drawtwo", 2] && [l, draw_kind] != ["drawfour", 4]
    count[index] -= draw_count
    draw_kind, draw_count = -1, 0
    index = (index + reverse) % n
  end
  # p! [l, index + 1, reverse, draw_kind, draw_count, count]
  reverse = 0 if time == m - 1
  case l
  when "number"
    count[index] += 1
    index = (index + reverse) % n
  when "drawtwo"
    if draw_kind == 2
      count[index] += 1
      draw_count += 2
    else
      count[index] += 1
      draw_kind, draw_count = 2, 2
    end
    index = (index + reverse) % n
  when "drawfour"
    if draw_kind == 4
      count[index] += 1
      draw_count += 4
    else
      count[index] += 1
      draw_kind, draw_count = 4, 4
    end
    index = (index + reverse) % n
  when "skip"
    count[index] += 1
    index = (index + reverse * 2) % n
  when "reverse"
    count[index] += 1
    reverse *= -1
    index = (index + reverse) % n
  end
end
puts [index + 1, count[index]].join(' ')
0