結果
問題 | No.636 硬貨の枚数2 |
ユーザー |
|
提出日時 | 2018-01-22 13:52:04 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,045 bytes |
コンパイル時間 | 990 ms |
コンパイル使用メモリ | 113,936 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 23:36:17 |
合計ジャッジ時間 | 2,738 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 WA * 35 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop, std.bitmanip;immutable int INF = 1 << 29;void main() {auto N = readln.chomp.to!(dchar[]);N.reverse;N ~= '0';auto dp = new int[][](N.length+1, 2);foreach (i; 0..N.length+1) dp[i].fill(INF);dp[0][0] = 0;foreach (i; 0..N.length) {foreach (j; 0..2) {int d = (N[i] - '0' + j) % 10;int x = INF;int y = INF;foreach (a; 0..10) {foreach (b; 0..9) {if ((a - b + 10) % 10 != d) continue;int c = a / 5 + a % 5 + b / 5 + b % 5;if (a >= b) x = min(x, c);else y = min(y, c);}}dp[i+1][0] = min(dp[i+1][0], dp[i][j] + x);dp[i+1][1] = min(dp[i+1][1], dp[i][j] + y);}}dp[N.length][0].writeln;}