結果

問題 No.636 硬貨の枚数2
ユーザー mamekinmamekin
提出日時 2018-02-04 18:12:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,145 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 103,136 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-12 16:04:34
合計ジャッジ時間 5,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0