結果

問題 No.634 硬貨の枚数1
ユーザー masakt
提出日時 2018-01-19 22:17:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 123,344 KB
実行使用メモリ 89,344 KB
最終ジャッジ日時 2024-12-25 19:14:46
合計ジャッジ時間 131,734 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 27 TLE * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define all(r) r.begin(),r.end()
using namespace std;
using ll = int64_t;
using vll = vector<ll>;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        vll dp(n + 1);
        fill(all(dp), -1);
        dp[0] = 0;
        for (int i = 1; i * (i + 1) / 2 <= n; i++) {
            for (int j = i * (i + 1) / 2; j <= n; j++) {
                if (dp[j] >= 0) {
                    dp[j] = i * (i + 1) / 2;
                }
                else {
                    dp[j] = dp[j - (i * (i + 1) / 2)] - 1;
                }
            }
        }
        out << -dp[n] << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}
0