結果
問題 |
No.636 硬貨の枚数2
|
ユーザー |
![]() |
提出日時 | 2017-05-10 17:44:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 895 bytes |
コンパイル時間 | 1,289 ms |
コンパイル使用メモリ | 167,640 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-19 10:22:47 |
合計ジャッジ時間 | 5,949 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 RE * 35 |
ソースコード
#include <iostream> #include <vector> #include <map> #include <assert.h> using namespace std; const vector<int> Z = {0,1,2,3,2,1,2,3,3,2,1}; const vector<int> C = {0,1,2,5,6,7}; const vector<int> X = {0,1,2,1,2,3}; #include <bits/stdc++.h> using namespace std; map<long long, int> memo; int solve_memorec(long long x) { if (x == 0) return 0; if (x < 10) return memo[x] = Z[x]; if (memo.count(x)) return memo[x]; int d = x % 10; long long r = x / 10; int ret = 1e9; for (int i = 0; i < 6; i++) { int cand; if (d + C[i] >= 10) { cand = solve_memorec(r+1) + X[i] + Z[d + C[i] - 10]; } else { cand = solve_memorec(r) + X[i] + Z[d + C[i]]; } ret = min(ret, cand); } return memo[x] = ret; } int main() { long long n; cin >> n; assert(n >= 1); assert(n <= 1000000000000000000LL); cout << solve_memorec(n) << endl; return 0; }