結果

問題 No.2078 魔抜けなパープル
ユーザー flygonflygon
提出日時 2022-09-25 22:17:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 385 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 86,424 KB
最終ジャッジ日時 2023-08-24 02:19:18
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
77,076 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 168 ms
84,436 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 223 ms
86,424 KB
testcase_07 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop
t = int(input())
for  i in range(t):
  x,a = map(int,input().split())
  INF = 10**18
  dp = [INF]*(a+1)
  dp[0] = 0
  ks = []
  border = int(x**0.5)+1
  for i in range(border-2, border+2):
    ks.append([i,i*i+x])
  for i in range(1,a+1):
    dp[i] = i*i+x
    for j,jc in ks:
      if j > i: break
      dp[i] = min(dp[i], dp[i-j]+ jc)
  print(dp[-1])


    
0