結果

問題 No.2078 魔抜けなパープル
ユーザー Navier_Boltzmann
提出日時 2022-09-25 22:56:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,367 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 92,416 KB
最終ジャッジ日時 2024-12-22 14:57:31
合計ジャッジ時間 6,437 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline


def answer():
    X,A = map(int,input().split())
    L = math.floor(math.sqrt(X))
    INF =  (1<<30)
    dp = [INF]*(A+1)
    
    dp[0] = 0
    for i in range(1,A+1):
        if i<L-10:
            dp[i] = i**2 + X
            continue
        dp[i] = min(k**2 + X + dp[i-k] for k in range(max(1,L-10),min(i,L+10)+1))
    print(dp[A])
for _ in range(int(input())):
    answer()
    

    
0