結果

問題 No.871 かえるのうた
ユーザー wipex
提出日時 2019-11-05 23:07:46
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 1,233 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 46,848 KB
最終ジャッジ日時 2024-09-15 00:15:06
合計ジャッジ時間 10,375 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 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]


update = true
@t=[[nil,0]]
xxx = @x.length

def aaa(elm)
 if @t.any? {|w,y| w == elm }
   return true
 else
   if @t[0][0]==nil
     @t=[[elm,0]]
   else
     @t.push([elm,0])
   end
   return false
 end
end

while(update)
  if @t[0][0]==nil
    b = @hash[p]
    zzz = p+b
    zzz1 = p+(-1*b)
    for i in 0...xxx do
      if zzz1 > zzz
        if @x[i] >=zzz and zzz1 >= @x[i]
          aaa(@x[i])
        end
      else
        if zzz >= @x[i] and @x[i] >= zzz1
          aaa(@x[i])
        end
      end
      break if i == xxx-1
    end
  else
    cnt = 0
    @t.each do |elm, elm2|
      next if elm2==1
      b = @hash[elm]
      zzz = elm+b
      zzz1 = elm+(-1*b)
      @t[cnt][1] = 1 
      for i in 0...xxx do
        update = false if i == xxx-1
        if zzz1 > zzz
          if @x[i] >=zzz and zzz1 >= @x[i]
            aaa(@x[i])
          end
        else
          if zzz >= @x[i] and @x[i] >= zzz1
            aaa(@x[i])
          end
        end
      end
      cnt+=1
    end
  end
end

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