結果

問題 No.2078 魔抜けなパープル
ユーザー やうやう
提出日時 2022-09-25 21:42:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 790 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 165,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 02:07:04
合計ジャッジ時間 6,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
4,376 KB
testcase_01 AC 790 ms
4,380 KB
testcase_02 AC 695 ms
4,384 KB
testcase_03 AC 674 ms
4,380 KB
testcase_04 AC 640 ms
4,376 KB
testcase_05 AC 691 ms
4,380 KB
testcase_06 AC 691 ms
4,376 KB
testcase_07 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
using V=vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)

void solve(){
    ll x,a,n=101010,inf=1e18;
    cin >> x >> a;
    V dp(n,inf);
    dp[0]=0;
    rep(j,n) if(j*j+x<dp[j]){
        ll i=0;
        while(i+j<n){
            dp[i+j]=min(dp[i+j],dp[i]+j*j+x);
            i++;
        }
    }
    cout << dp[a] << endl;
}

int main(){
    int t;
    cin >> t;
    rep(i,t) solve();
}
0