結果

問題 No.636 硬貨の枚数2
ユーザー polylogKpolylogK
提出日時 2020-04-16 15:16:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,217 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 169,992 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 19:12:06
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
6,940 KB
testcase_18 WA -
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
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 AC 4 ms
6,940 KB
testcase_45 AC 3 ms
6,940 KB
testcase_46 AC 3 ms
6,944 KB
testcase_47 AC 3 ms
6,940 KB
testcase_48 AC 3 ms
6,940 KB
testcase_49 AC 3 ms
6,940 KB
testcase_50 AC 3 ms
6,940 KB
testcase_51 AC 3 ms
6,940 KB
testcase_52 AC 3 ms
6,940 KB
testcase_53 AC 3 ms
6,940 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 AC 2 ms
6,944 KB
testcase_58 AC 2 ms
6,940 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 2 ms
6,944 KB
testcase_61 AC 2 ms
6,944 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 1 ms
6,940 KB
testcase_64 AC 4 ms
6,944 KB
testcase_65 AC 3 ms
6,944 KB
testcase_66 AC 3 ms
6,940 KB
testcase_67 AC 3 ms
6,944 KB
testcase_68 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	reverse(begin(s), end(s));
	s += '0';

	auto dp = make_v<int>(s.size() + 1, 2);
	for(int i = 0; i < (int)dp.size(); i++) for(int j = 0; j < (int)dp[i].size(); j++) dp[i][j] = 1 << 30;
	dp[0][0] = 0;

	std::vector<int> cost = {0, 1, 2, 3, 4, 1, 2, 3, 4, 5, 2};
	for(int i = 0; i < (int)s.size(); i++) {
		int d = s[i] - '0';

		for(int j = d; j <= 10; j++) {
			dp[i + 1][0] = std::min(dp[i + 1][0], dp[i][0] + cost[j] + cost[j - d]);
			if(j != d) dp[i + 1][0] = std::min(dp[i + 1][0], dp[i][1] + cost[j] + cost[j - d]);
		}

		for(int j = 0; j <= d; j++) {
			dp[i + 1][1] = std::min(dp[i + 1][1], dp[i][1] + cost[j] + cost[9 - (d - j)]);
			dp[i + 1][1] = std::min(dp[i + 1][1], dp[i][0] + cost[j] + cost[9 - (d - j)]);
		}
	}
	
	printf("%d\n", dp[(int)s.size()][0]);
	return 0;
}
0