ソースコード 拡げる

Copy
```#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 1000000 + 1000;
i64 dp[maxn][2];
char s[maxn];

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
#endif

cin >> (s + 1);
int len = strlen(s + 1);
dp[len][0] = s[len] - '0';
dp[len][1] = 10 - (s[len] - '0');
for (int i = len - 1; i >= 1; --i) {
int num = s[i] - '0';
dp[i][0] = min(dp[i + 1][0] + num, dp[i + 1][1] + num + 1);
dp[i][1] = min(dp[i + 1][0] + (10 - num), dp[i + 1][1] + (10 - num - 1));
}
cout << min(dp[1][0], dp[1][1] + 1) << '\n';

#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
```

#### 提出情報

提出日時 2020-02-21 04:42:52+0900 E - Payment maxzzy8 C++14 (GCC 5.4.1) 500 1797 Byte AC 10 ms 16896 KB

#### ジャッジ結果

 AC × 3
 AC × 41
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
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 10 ms 16896 KB
sub1_06.txt AC 10 ms 16896 KB
sub1_07.txt AC 10 ms 16896 KB
sub1_08.txt AC 10 ms 16896 KB
sub1_09.txt AC 10 ms 16896 KB
sub1_10.txt AC 10 ms 16896 KB
sub1_11.txt AC 1 ms 512 KB
sub1_12.txt AC 5 ms 7936 KB
sub1_13.txt AC 5 ms 7808 KB
sub1_14.txt AC 1 ms 640 KB
sub1_15.txt AC 2 ms 1408 KB
sub1_16.txt AC 5 ms 7808 KB
sub1_17.txt AC 10 ms 16896 KB
sub1_18.txt AC 5 ms 7936 KB
sub1_19.txt AC 10 ms 16896 KB
sub1_20.txt AC 8 ms 14336 KB
sub1_21.txt AC 5 ms 7808 KB
sub1_22.txt AC 10 ms 16896 KB
sub1_23.txt AC 5 ms 7808 KB
sub1_24.txt AC 5 ms 7808 KB
sub1_25.txt AC 10 ms 16896 KB
sub1_26.txt AC 3 ms 3584 KB
sub1_27.txt AC 7 ms 12160 KB
sub1_28.txt AC 10 ms 16896 KB
sub1_29.txt AC 3 ms 3456 KB
sub1_30.txt AC 7 ms 12160 KB
sub1_31.txt AC 7 ms 12288 KB
sub1_32.txt AC 10 ms 16896 KB
sub1_33.txt AC 8 ms 14464 KB
sub1_34.txt AC 3 ms 3584 KB
sub1_35.txt AC 8 ms 14336 KB
sub1_36.txt AC 7 ms 12160 KB
sub1_37.txt AC 10 ms 16896 KB
sub1_38.txt AC 10 ms 16896 KB