結果

問題 No.636 硬貨の枚数2
ユーザー 0w1
提出日時 2019-08-02 14:29:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 736 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 198,432 KB
最終ジャッジ日時 2025-01-07 10:32:37
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  string N;
  cin >> N;

  vector<vector<int>> dp(N.size() + 1, vector<int>(2, 0x3f3f3f3f));
  dp[0][0] = 0;
  dp[0][1] = 1;
  for (int i = 0; i < N.size(); ++i) {
    int cs[] = { 0, 1, 5 };
    auto cc = [&cs](int x) {
      assert(-1 < x && x < 11);
      return x % 10 / 5 + x % 5;
    };
    for (int d = 0; d < 11; ++d) {
      if (N[i] - '0' <= d) {
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][d == 10] + cc(d) + cc(d - (N[i] - '0')));
      }
      if (N[i] - '0' < d) {
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][d == 10] + cc(d) + cc(d - (N[i] - '0') - 1));
      }
    }
  }

  cout << dp[N.size()][0] << endl;

  return 0;
}
0