結果

問題 No.2078 魔抜けなパープル
ユーザー flygonflygon
提出日時 2022-09-25 22:21:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 558 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 86,188 KB
最終ジャッジ日時 2023-08-24 02:20:13
合計ジャッジ時間 3,454 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
76,808 KB
testcase_01 AC 398 ms
84,740 KB
testcase_02 AC 307 ms
82,264 KB
testcase_03 AC 354 ms
84,420 KB
testcase_04 AC 287 ms
81,940 KB
testcase_05 AC 292 ms
82,112 KB
testcase_06 AC 558 ms
86,188 KB
testcase_07 AC 168 ms
81,860 KB
権限があれば一括ダウンロードができます

ソースコード

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-10, border+10):
    if i <= 0: continue
    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