포럼
문제 ICPC00272

K. Keep Calm And Carry Off

설명

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
예제 2
입력
90
10
출력
10
예제 3
입력
23425
487915
출력
12085
문제 정보

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

출처 ICPC NCPC 2020

평가 및 의견

K. Keep Calm And Carry Off

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

Log in to rate problems.

개별 의견

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

풀이 제출

K. Keep Calm And Carry Off

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