結果
| 問題 | No.331 CodeRunnerでやれ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-24 05:34:18 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,055 bytes |
| 記録 | |
| コンパイル時間 | 141 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 91,988 KB |
| 平均クエリ数 | 6.12 |
| 最終ジャッジ日時 | 2024-07-16 22:34:28 |
| 合計ジャッジ時間 | 8,109 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 TLE * 1 -- * 13 |
ソースコード
#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def gfs() gss.map(&:to_f) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end
############################################################
f = arr2d(60, 60)
x = 30
y = 30
dx = 1
dy = 0
def rot(dx, dy) [-dy, dx] end
def revrot(dx, dy) [dy, -dx] end
def rcell(f, x, y, dx, dy)
nx, ny = rot(dx, dy)
f[y + ny][x + nx]
end
def lcell(f, x, y, dx, dy)
nx, ny = revrot(dx, dy)
f[y + ny][x + nx]
end
UNKNOWN_CELL = 0
WALL_CELL = 1
SPACE_CELL = 2
t = 0
loop {
s = STDIN.gets
break if s[0] == "M"
if s.size > 2
STDOUT.puts "F"
else
d = s.to_i
if f[y + dy][x + dx] == UNKNOWN_CELL
(1..d).each do |i|
f[y + dy * i][x + dx * i] = SPACE_CELL
end
f[y + dy * d.succ][x + dx * d.succ] = WALL_CELL
end
nxt = "X"
case t
when 0
if d == 0
if rcell(f, x, y, dx, dy) == UNKNOWN_CELL
nxt = "R"
else
nxt = "L"
end
else
nxt = "F"
t = 1
end
when 1
t = 2
if rcell(f, x, y, dx, dy) == UNKNOWN_CELL
nxt = "R"
elsif lcell(f, x, y, dx, dy) == UNKNOWN_CELL
nxt = "L"
elsif d > 0
nxt = "F"
t = 0
elsif rcell(f, x, y, dx, dy) == SPACE_CELL
nxt = "R"
t = 0
elsif lcell(f, x, y, dx, dy) == SPACE_CELL
nxt = "L"
t = 0
else
nxt = "B"
t = 3
end
when 2
if d == 0
nxt = "L"
else
nxt = "F"
end
t = 0
when 3
if rcell(f, x, y, dx, dy) == UNKNOWN_CELL
nxt = "R"
t = 0
elsif lcell(f, x, y, dx, dy) == UNKNOWN_CELL
nxt = "L"
t = 0
elsif f[y - dy][x - dx] == WALL_CELL
nxt = "RL"[rand(2)]
t = 0
else
nxt = "B"
end
end
case nxt
when "F"
x += dx
y += dy
when "R"
dx, dy = rot(dx, dy)
when "B"
x -= dx
y -= dy
when "L"
dx, dy = revrot(dx, dy)
end
puts nxt
end
STDOUT.flush
}