Submission #10226643


Source Code Expand

Copy
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    string N;
    cin >> N;
    vector<vector<int>> dp(N.size()+1,vector<int>(2,0));
    dp[0][1] = 1;
    FOR(i,1,N.size()+1) {
        int Ni = N[i-1] - '0';
        dp[i][0] = min(dp[i-1][0]+Ni,dp[i-1][1]+10-Ni);
        dp[i][1] = min(dp[i-1][0]+Ni+1,dp[i-1][1]+10-Ni-1);
    }
    cout << dp[N.size()][0] << endl;
    return 0;
}

Submission Info

Submission Time
Task E - Payment
User reud
Language C++14 (GCC 5.4.1)
Score 500
Code Size 938 Byte
Status AC
Exec Time 98 ms
Memory 55940 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 41
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, sample_03.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt, sub1_31.txt, sub1_32.txt, sub1_33.txt, sub1_34.txt, sub1_35.txt, sub1_36.txt, sub1_37.txt, sub1_38.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sub1_01.txt AC 1 ms 256 KB
sub1_02.txt AC 1 ms 256 KB
sub1_03.txt AC 1 ms 256 KB
sub1_04.txt AC 1 ms 256 KB
sub1_05.txt AC 95 ms 55940 KB
sub1_06.txt AC 96 ms 55940 KB
sub1_07.txt AC 95 ms 55940 KB
sub1_08.txt AC 95 ms 55940 KB
sub1_09.txt AC 96 ms 55940 KB
sub1_10.txt AC 95 ms 55940 KB
sub1_11.txt AC 3 ms 1280 KB
sub1_12.txt AC 40 ms 23556 KB
sub1_13.txt AC 39 ms 22532 KB
sub1_14.txt AC 3 ms 1408 KB
sub1_15.txt AC 8 ms 3968 KB
sub1_16.txt AC 39 ms 22788 KB
sub1_17.txt AC 95 ms 55940 KB
sub1_18.txt AC 39 ms 22788 KB
sub1_19.txt AC 95 ms 55940 KB
sub1_20.txt AC 75 ms 43524 KB
sub1_21.txt AC 35 ms 20484 KB
sub1_22.txt AC 95 ms 55940 KB
sub1_23.txt AC 35 ms 20100 KB
sub1_24.txt AC 37 ms 21380 KB
sub1_25.txt AC 98 ms 55940 KB
sub1_26.txt AC 18 ms 9988 KB
sub1_27.txt AC 60 ms 34692 KB
sub1_28.txt AC 95 ms 55940 KB
sub1_29.txt AC 14 ms 7424 KB
sub1_30.txt AC 60 ms 34692 KB
sub1_31.txt AC 65 ms 37892 KB
sub1_32.txt AC 95 ms 55940 KB
sub1_33.txt AC 80 ms 46724 KB
sub1_34.txt AC 18 ms 9988 KB
sub1_35.txt AC 77 ms 44548 KB
sub1_36.txt AC 61 ms 35844 KB
sub1_37.txt AC 95 ms 55940 KB
sub1_38.txt AC 95 ms 55940 KB