포럼
문제 ICPC00321

E. Efficient Exchange

설명

You have recently acquired a new job at the Bank for Acquiring Peculiar Currencies. Here people can make payments, and deposit or withdraw money in all kinds of strange currencies. At your first day on the job you help a customer from Nijmegia, a small insignificant country famous for its enormous coins with values equal to powers of 10, that is, \(1, 10, 100, 1000\), etc. This customer wants to make a rather large payment, and you are not looking forward to the prospect of carrying all those coins to and from the vault.

You therefore decide to think things over first. You have an enormous supply of Nijmegian coins in reserve, as does the customer (most citizens from Nijmegia are extremely strong). You now want to minimize the total number of coins that are exchanged, in either direction, to make the exact payment the customer has to make.

For example, if the customer wants to pay 83 coins there are many ways to make the exchange. Here are three possibilities:
- The customer pays \(8\) coins of value \(10\), and \(3\) coins of value \(1\). This requires exchanging \(8 + 3 = 11\) coins.
- The customer pays a coin of value \(100\), and you return a coin of value \(10\), and \(7\) coins of value \(1\). This requires exchanging \(1 + 1 + 7 = 9\) coins.
- The customer pays a coin of value \(100\), and \(3\) coins of value \(1\). You return \(2\) coins of value \(10\). This requires exchanging \(1 + 3 + 2 = 6\) coins.

It turns out the last way of doing it requires the least coins possible.

제약
입력 형식
  • A single integer \(0\leq n < 10^{1000}\), the amount the customer from Nijmegia has to pay.
출력 형식
  • Output the minimum number of coins that have to be exchanged to make the required payment.
예제 1
입력
83
출력
6
예제 2
입력
13
출력
4
예제 3
입력
0
출력
0
예제 4
입력
12345678987654321
출력
42
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2019

평가 및 의견

E. Efficient Exchange

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

E. Efficient Exchange

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8