結果
問題 |
No.634 硬貨の枚数1
|
ユーザー |
![]() |
提出日時 | 2018-01-19 22:01:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,099 bytes |
コンパイル時間 | 1,051 ms |
コンパイル使用メモリ | 83,224 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-25 18:55:29 |
合計ジャッジ時間 | 2,692 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 58 |
ソースコード
#include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <bitset> #include <algorithm> using namespace std; #define REP(i,n) for(int i=0; i<n; ++i) #define FOR(i,a,b) for(int i=a; i<=b; ++i) #define FORR(i,a,b) for (int i=a; i>=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef vector<VI> VVI; typedef pair<int,int> P; typedef pair<ll,ll> PL; VI tri; int dp[100000001]; int calc(int n){ if (n == 0) return 0; // cout << n << endl; if (dp[n]) return dp[n]; int p = upper_bound(ALL(tri), n) - tri.begin() - 1; int ret = calc(n - tri[p]) + 1; if (p) ret = min(ret, calc(n - tri[p - 1]) + 1); return dp[n] = ret; } int main() { int n; cin >> n; FOR(i,1,100000){ int x = i * (i+1) / 2; if (x > n) break; tri.push_back(x); } cout << calc(n) << endl; return 0; }