結果
問題 | No.636 硬貨の枚数2 |
ユーザー |
|
提出日時 | 2018-02-04 18:12:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,145 bytes |
コンパイル時間 | 975 ms |
コンパイル使用メモリ | 104,264 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-30 04:00:45 |
合計ジャッジ時間 | 2,899 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 24 WA * 41 |
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> #include <iterator> using namespace std; const int INF = INT_MAX / 2; int solve(int x) { if(x < 0) return INF; else if(x < 5) return x; else return x - 4; } int main() { string s; cin >> s; int n = s.size(); vector<int> dp(2, 0); dp[1] = 1; for(int i=n-1; i>=0; --i){ vector<int> nextDp(2, INF); for(int a=0; a<2; ++a){ for(int b=0; b<10; ++b){ int x = a * 10 + b - (s[i] - '0'); nextDp[0] = min(nextDp[0], dp[a] + solve(b) + solve(x)); nextDp[1] = min(nextDp[1], dp[a] + solve(b) + solve(x - 1)); } } dp.swap(nextDp); } cout << dp[0] << endl; return 0; }