Logo
(追記) (追記ここまで)

21057번 - Keep Calm And Carry Off 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB104423355.932%

문제

Petra is learning how to add two positive integers in school, but thinks it is a bit too difficult. They are currently working with the standard algorithm for addition, where you first compute the sum of the two units digits, then the sum of the two tens digits, and so on. Whenever the sum of the digits at the same position in the two numbers exceeds 9, a carry digit is added onto the digit of the next higher magnitude. Petra has trouble with the last step -- she often forgets to keep track of the carry digit.

A few weeks ago, she also learnt a simpler method of addition. In this method, you repeatedly add 1ドル$ to one of the numbers and subtract 1ドル$ from the other, until the second one reaches zero. This can of course take a lot of time for large numbers.

Petra now wants to combine the two methods, for fast and error-free addition. Her plan is to first perform the second method one step at a time, until the two numbers would not produce a carry digit when added using the standard algorithm (for positive integers, this always happens eventually). To evaluate the performance of her new method, she has asked you to help her compute the number of steps she must perform of the second method when adding two given integers. Petra may perform the addition by 1ドル$ to either of the two numbers (and subtraction by 1ドル$ from the other).

입력

The input consists of two lines, each containing a positive integer with at most 10ドル^6$ digits. These are the two integers Petra wants to add.

출력

Output a single integer, the minimum number of times Petra must add 1ドル$ to one of her numbers (while subtracting 1ドル$ from the other) until they can be added using the standard addition algorithm without any carry digits.

제한

예제 입력 1

10
99

예제 출력 1

1

예제 입력 2

90
10

예제 출력 2

10

예제 입력 3

23425
487915

예제 출력 3

12085

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2020 K번

Camp > Petrozavodsk Programming Camp > Winter 2021 > Day 3: Nordic+ Contest 2020 K번

  • 문제를 만든 사람: Johan Sannemo
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /