結果

問題 No.871 かえるのうた
ユーザー wipex
提出日時 2019-11-04 15:32:18
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 1,916 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 46,336 KB
最終ジャッジ日時 2024-09-14 23:42:21
合計ジャッジ時間 11,244 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 1 TLE * 1 -- * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.compact!
   @t<<elm
   return false
 end
end

update = true
@t=[nil]

while(update)
  if @t[0]==nil
    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
              break
            else
              next
            end
          else
            p = @x[i]
            break
          end
        elsif i == xxx-1
          break
        end
      else
        if zzz >= @x[i].to_i and @x[i].to_i >= zzz1
          if aaa(@x[i])== true
            if i == xxx-1
              break
            else
              next
            end
          else
            p = @x[i]
            break
          end
        elsif i == xxx-1
          break
        end
      end
    end
  else
    @t.each do |elm|
      b = @hash[elm]
      zzz = elm+b
      zzz1 = elm+(-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
            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
            end
          elsif i == xxx-1
            update = false
          end
        end
      end
    end
  end
end

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