結果

問題 No.634 硬貨の枚数1
ユーザー merom686
提出日時 2018-01-19 22:02:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 716 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 75,716 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-25 18:56:23
合計ジャッジ時間 8,874 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 72 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;

    int m = 155000;
    vector<int> a(m);
    a[0] = 0;
    for (int i = 1; i < m; i++) {
        int x = 1 << 30;
        for (int k = 1;; k++) {
            int l = k * (k + 1) / 2;
            if (l > i) break;
            x = min(x, a[i - l] + 1);
        }
        a[i] = x;
    }

    int i = n;
    int x = 1 << 30;
    for (int k = 1;; k++) {
        int l = k * (k + 1) / 2;
        if (l > i) break;
        if (i - l >= m) continue;
        x = min(x, a[i - l] + 1);
    }

    cout << x << endl;

    return 0;
}
0