結果

問題 No.634 硬貨の枚数1
ユーザー tokizo
提出日時 2019-03-09 18:51:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 613 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 170,624 KB
実行使用メモリ 43,220 KB
最終ジャッジ日時 2024-06-23 15:14:43
合計ジャッジ時間 8,273 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 TLE * 2 -- * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> A;
    int t, c = 1;
    while(true){
        t = c * (c + 1) / 2;
        if(t > n) break;
        A.push_back(t);
        c++;
    }

    int dp[n + 1];
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        dp[i] = 1e9;
    }

    dp[1] = 1;
    for(int i = 1; i <= n; i++){
        for(auto x : A){
            if(i - x >= 0){
                dp[i] = min(dp[i], dp[i - x] + 1);
            }
        }
    }

    cout << dp[n] << endl;

    return 0;
}
0