結果

問題 No.331 CodeRunnerでやれ
ユーザー simansiman
提出日時 2022-07-27 00:59:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 668 ms / 5,000 ms
コード長 706 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 11,384 KB
実行使用メモリ 31,416 KB
平均クエリ数 721.65
最終ジャッジ日時 2023-09-24 03:04:56
合計ジャッジ時間 8,776 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 248 ms
30,960 KB
testcase_01 AC 244 ms
31,272 KB
testcase_02 AC 277 ms
31,376 KB
testcase_03 AC 274 ms
31,084 KB
testcase_04 AC 282 ms
31,412 KB
testcase_05 AC 288 ms
31,076 KB
testcase_06 AC 290 ms
31,372 KB
testcase_07 AC 388 ms
31,384 KB
testcase_08 AC 586 ms
31,204 KB
testcase_09 AC 351 ms
31,108 KB
testcase_10 AC 405 ms
30,660 KB
testcase_11 AC 668 ms
31,340 KB
testcase_12 AC 421 ms
31,176 KB
testcase_13 AC 398 ms
31,356 KB
testcase_14 AC 392 ms
31,012 KB
testcase_15 AC 406 ms
31,416 KB
testcase_16 AC 355 ms
30,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def send_query(str)
  STDOUT.puts(str)
  STDOUT.flush

  res = gets.chomp

  if res == "Merry Christmas!"
    -1
  else
    res.to_i
  end
end

v = gets.to_i
v.times do
  res = send_query("F")
  exit if res == -1
end

send_query("R")
step_cnt = 0

loop do
  res = send_query("L")

  if res > 0 && step_cnt > 1000
    res.times do
      f = send_query("F")
      exit if f == -1
    end

    send_query("R")
    step_cnt = 0
    next
  end

  if res > 0
    f = send_query("F")
    step_cnt += 1

    if f < 0
      exit
    end
  else
    f = send_query("R")

    if f > 0
      r = send_query("F")
      step_cnt += 1
      if r < 0
        exit
      end
    else
      send_query("R")
    end
  end
end
0