Submission #10163618


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














string N;
int dp[1010101][2];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	reverse(all(N));

	int n = N.length();
	rep(i, 0, n + 1) rep(d, 0, 2) dp[i][d] = inf;
	dp[0][0] = 0;
	rep(i, 0, n) rep(d, 0, 2) if (dp[i][d] != inf) {
		int c = N[i] - '0' + d;
		if(d == 10) chmin(dp[i + 1][0], dp[i][d] + c);
		chmin(dp[i + 1][1], dp[i][d] + 10 - c);
	}

	int ans = min(dp[n][0], dp[n][1] + 1);
	cout << ans << endl;
}





Submission Info

Submission Time
Task E - Payment
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1801 Byte
Status WA
Exec Time 9 ms
Memory 9244 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 0 / 500
Status
WA × 3
AC × 7
WA × 34
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 WA 1 ms 256 KB
sample_02.txt WA 1 ms 256 KB
sample_03.txt WA 1 ms 256 KB
sub1_01.txt WA 1 ms 256 KB
sub1_02.txt WA 1 ms 256 KB
sub1_03.txt AC 1 ms 256 KB
sub1_04.txt AC 1 ms 256 KB
sub1_05.txt WA 9 ms 9116 KB
sub1_06.txt WA 9 ms 9116 KB
sub1_07.txt WA 9 ms 9244 KB
sub1_08.txt WA 9 ms 9244 KB
sub1_09.txt WA 9 ms 9116 KB
sub1_10.txt WA 9 ms 9244 KB
sub1_11.txt WA 1 ms 384 KB
sub1_12.txt WA 5 ms 4892 KB
sub1_13.txt WA 5 ms 4892 KB
sub1_14.txt WA 1 ms 512 KB
sub1_15.txt WA 2 ms 896 KB
sub1_16.txt WA 5 ms 4892 KB
sub1_17.txt WA 9 ms 9244 KB
sub1_18.txt AC 5 ms 4892 KB
sub1_19.txt AC 9 ms 9116 KB
sub1_20.txt WA 7 ms 7324 KB
sub1_21.txt WA 4 ms 4884 KB
sub1_22.txt WA 9 ms 9244 KB
sub1_23.txt AC 4 ms 4884 KB
sub1_24.txt AC 4 ms 4884 KB
sub1_25.txt AC 9 ms 9116 KB
sub1_26.txt WA 3 ms 1872 KB
sub1_27.txt WA 6 ms 7068 KB
sub1_28.txt WA 9 ms 9244 KB
sub1_29.txt WA 2 ms 1488 KB
sub1_30.txt WA 6 ms 7068 KB
sub1_31.txt WA 7 ms 7196 KB
sub1_32.txt WA 9 ms 9116 KB
sub1_33.txt WA 8 ms 7708 KB
sub1_34.txt WA 3 ms 1872 KB
sub1_35.txt WA 7 ms 7452 KB
sub1_36.txt WA 6 ms 7196 KB
sub1_37.txt WA 9 ms 9116 KB
sub1_38.txt WA 9 ms 9116 KB