oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

calculator2 Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

calculator2.html

Title

Problem Statement

Snuke has a calculator. It has a display and two buttons.

Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:

  • Button A: When pressed, the value on the display is incremented by 1.
  • Button B: When pressed, the sign of the value on the display is reversed.

Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.

Constraints

  • x and y are integers.
  • |x|, |y| ≤ 109
  • x and y are different.

Input

The input is given from Standard Input in the following format:

x y

Output

Print the minimum number of times Snuke needs to press the buttons to achieve his objective.

Sample Input 1

10 20

Sample Output 1

10

Press button A ten times.

Sample Input 2

10 -10

Sample Output 2

1

Press button B once.

Sample Input 3

-10 -20

Sample Output 3

12

Press the buttons as follows:

  • Press button B once.
  • Press button A ten times.
  • Press button B once.

Sample Input 4

20 10

Sample Output 4

12

Sample Input 5

-20 -10

Sample Output 5

10

Sample Input 6

20 -10

Sample Output 6

11

Sample Input 7

-20 10

Sample Output 7

11

Sample Input 8

10 -20

Sample Output 8

11

Sample Input 9

0 10

Sample Output 9

10

Sample Input 10

-10 0

Sample Output 10

10

Tags

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
1100141s256MBAverage
2031s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o calculator2 -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.