結果

問題 No.561 東京と京都
ユーザー hoktohokto
提出日時 2020-03-25 13:06:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 11,576 KB
実行使用メモリ 15,308 KB
最終ジャッジ日時 2023-08-30 09:31:50
合計ジャッジ時間 3,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,044 KB
testcase_01 AC 81 ms
15,128 KB
testcase_02 AC 82 ms
15,308 KB
testcase_03 AC 81 ms
15,056 KB
testcase_04 AC 81 ms
15,032 KB
testcase_05 AC 80 ms
15,148 KB
testcase_06 AC 79 ms
15,296 KB
testcase_07 AC 81 ms
15,240 KB
testcase_08 AC 79 ms
15,148 KB
testcase_09 AC 80 ms
15,036 KB
testcase_10 AC 80 ms
15,088 KB
testcase_11 AC 81 ms
15,296 KB
testcase_12 AC 81 ms
15,104 KB
testcase_13 AC 82 ms
15,064 KB
testcase_14 AC 84 ms
15,040 KB
testcase_15 AC 82 ms
15,132 KB
testcase_16 AC 83 ms
15,148 KB
testcase_17 AC 82 ms
15,148 KB
testcase_18 AC 83 ms
15,036 KB
testcase_19 AC 84 ms
15,308 KB
testcase_20 AC 83 ms
15,156 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end
N,D=get_i
tk=array(N)
N.times do|i|
    tk[i]=get_i
end
dp=array(2,0,N+1)
dp[1][0]=tk[0][0]
dp[1][1]=tk[0][1]-D
2.upto(N) do|i|
  2.times do|j|
      dp[i][j]=max(dp[i-1][j]+tk[i-1][j],dp[i-1][(j+1)%2]-D+tk[i-1][j])
  end 
end
puts dp[N].max
0