結果

問題 No.2622 Dam
ユーザー kotatsugamekotatsugame
提出日時 2024-02-09 21:30:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-02-09 21:31:11
合計ジャッジ時間 1,121 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
16,256 KB
testcase_01 AC 78 ms
16,384 KB
testcase_02 AC 75 ms
16,384 KB
testcase_03 AC 78 ms
16,384 KB
testcase_04 AC 80 ms
16,384 KB
testcase_05 AC 76 ms
16,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

gets.to_i.times{
  v,x,fo,fi,q,r=gets.split.map &:to_i
  old_x=x
  x+=(fi-fo)*r
  if x>v
    puts "Overflow"
    next
  end
  x-=fo*(q-r)
  if x<0
    puts "Zero"
    next
  end
  t=10**100-q
  if old_x<x
    d=x-old_x
    need=(v-x)/d
    t-=need*q
    x+=need*d
    needa=(v-x)/(fi-fo)+1
    t-=needa
    x+=needa*(fi-fo)
    if t>=0
      puts "Overflow"
    else
      puts "Safe"
    end
  elsif old_x>x
    d=old_x-x
    need=x/d
    t-=need*q
    x-=need*d
    if fi>=fo
      t-=r
      x+=(fi-fo)*r
    else
      v=[x/(fo-fi)+1,r].min
      t-=v
      x-=(fo-fi)*v
    end
    needa=x/fo+1
    t-=needa
    x-=needa*fo
    if t>=0
      puts "Zero"
    else
      puts "Safe"
    end
  else
    puts "Safe"
  end
}
0