結果

問題 No.636 硬貨の枚数2
ユーザー kkktymkkktym
提出日時 2020-11-10 00:06:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,033 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 105,936 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-29 23:06:11
合計ジャッジ時間 5,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 WA -
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 1 ms
4,380 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 3 ms
4,376 KB
testcase_66 AC 3 ms
4,376 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  string s; cin >> s;
  int n = sz(s);

  vvl dp1(2, vl(2, infll/2));
  dp1[0][0] = 0;
  dp1[1][0] = 1;
  rep(i,n) {
    vvl dp2(2, vl(2, infll/2));
    int c = int(s[i] - '0');
    rep(j,10) {
      if(c < j) {
	if(c+1 < j) chmin(dp2[1][1], dp1[0][0] + j/5 + j%5 + (j-c-1)/5 + (j-c-1)%5);
	chmin(dp2[1][1], dp1[1][0] + j/5 + j%5 + (j-c-1)/5 + (j-c-1)%5);	      
	chmin(dp2[1][0], dp1[1][0] + j/5 + j%5 + (j-c)/5 + (j-c)%5);
	chmin(dp2[1][0], dp1[0][0] + j/5 + j%5 + (j-c)/5 + (j-c)%5);	
      }
      if(c == j) {
	chmin(dp2[1][1], dp1[1][0] + j/5 + j%5 + (9)/5 + (9)%5);
	chmin(dp2[1][0], dp1[1][0] + j/5 + j%5);
	chmin(dp2[0][0], dp1[0][0] + j/5 + j%5);
      }
      if(c > j) {
	chmin(dp2[1][1], dp1[1][0] + j/5 + j%5 + (9 + j - c)/5 + (9 + j - c)%5);
	chmin(dp2[1][1], dp1[1][1] + j/5 + j%5 + (9 + j - c)/5 + (9 + j - c)%5);
	chmin(dp2[1][0], dp1[1][0] + j/5 + j%5 + (10 + j - c)/5 + (10 + j - c)%5);
	chmin(dp2[1][0], dp1[1][1] + j/5 + j%5 + (10 + j - c)/5 + (10 + j - c)%5);		
      }
    }
    swap(dp1, dp2);
    //    cout << i << ":" << dp1[0][0] << ":" << dp1[1][0] << ";" << dp1[0][1] << ":" << dp1[1][1] << "\n";
  }
  cout << min(dp1[0][0], dp1[1][0]) << "\n";
  
  return 0;
}
0