結果
| 問題 | No.634 硬貨の枚数1 |
| コンテスト | |
| ユーザー |
しらっ亭
|
| 提出日時 | 2017-05-10 16:20:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 599 bytes |
| コンパイル時間 | 884 ms |
| コンパイル使用メモリ | 63,532 KB |
| 実行使用メモリ | 50,688 KB |
| 最終ジャッジ日時 | 2024-12-25 18:18:59 |
| 合計ジャッジ時間 | 138,720 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 TLE * 46 |
ソースコード
// 想定TLE解法
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solve(int n) {
vector<int> T;
for (int t, i = 1; (t = i * (i + 1) / 2) <= n; i++) {
T.emplace_back(t);
}
int m = (int) T.size();
const int inf = 1e9;
vector<int> dp(n + 1, inf);
dp[0] = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (dp[j] < inf) {
int k = j + T[i];
if (k > n) break;
dp[k] = min(dp[k], dp[j] + 1);
}
}
}
return dp[n];
}
int main() {
int n;
cin >> n;
cout << solve(n) << endl;
}
しらっ亭