結果

問題 No.871 かえるのうた
ユーザー wipex
提出日時 2019-11-04 09:21:20
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 1,772 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 41,472 KB
最終ジャッジ日時 2024-09-14 23:37:15
合計ジャッジ時間 10,096 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 11 TLE * 2 -- * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

@x=[];a=[];@t=[]
n,k = gets.chomp.split(" ").map(&:to_i)
@x+=gets.chomp.split(" ").map(&:to_i)
a+=gets.chomp.split(" ").map(&:to_i)
@hash = Hash[*([@x,a].transpose.flatten)]
p=@x[k-1]

def aaa(elm)
 if @t.any? {|w| w == elm }
   return true
 else
   @t<<elm
   return false
 end
end

update = true
while(update)
  b = @hash[p]
  zzz = p+b
  zzz1 = p+(-1*b)
  xxx = @x.length
  for i in 0...xxx do
    if zzz1 > zzz
      if @x[i] >=zzz and zzz1 >= @x[i]
        if aaa(@x[i])== true
          if i == xxx-1
            update = false
          else
            next
          end
        else
          p = @x[i]
        end
      elsif i == xxx-1
        update = false
      end
    else
      if zzz >= @x[i].to_i and @x[i].to_i >= zzz1
        if aaa(@x[i])== true
          if i == xxx-1
            update = false
          else
            next
          end
        else
          p = @x[i]
        end
      elsif i == xxx-1
        update = false
      end
    end
  end
end

pp=@x[k-1]
#@t.compact!
@y = @x.reverse

update = true
while(update)
  c = @hash[pp]
  zzz = pp+c
  zzz1 = pp+(-1*c)
  yyy = @y.length
  for i in 0...yyy do
    if zzz1 > zzz
      if @y[i] >=zzz and zzz1 >= @y[i]
        if aaa(@y[i])== true
          if i== yyy-1
            update = false
          else
            next
          end
        else
          pp = @y[i]
        end
      elsif i == yyy-1
        update = false
      end
    else
      if zzz >= @y[i].to_i and @y[i].to_i >= zzz1
        if aaa(@y[i])== true
          if i== yyy-1
            update = false
          else
            next
          end
        else
          pp = @y[i]
        end
      elsif i == yyy-1
        update = false
      end
    end
  end
end

if @t==nil
 p "1"
else
 p @t.length
end
0