시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 76 63 51 83.607%

문제

애벌레는 배가 고프다 

애벌레 앞에는 M개의 행과 N개의 열으로 이루어진 곳에 초콜렛이 놓여져 있다.

왼쪽 위에서 먹기 시작하여 모든 열을 지난다. 열의 끝에 다다르면 시계방향으로 행으로 내려가면서 먹기 시작한다.

행의 끝에 다다르면 같은 과정을 계속해서 반복한다.

이 과정을 반복하면서 마지막 열의끝에 도착하면 모든 초콜렛을 먹게 된다.

애벌레가 모든 초콜렛을 먹기 위해서 방향을 바꾸는 횟수는 몇번인지 계산하는 프로그램을 작성해야한다.

입력

첫번째 줄에 정수 M 과 N이 띄어쓰기로 구분되어 주어진다. (2  M,N ≤ 100)

M이 행이고 N이 열이다.

출력

첫번째 줄에 모든 초콜렛을 먹기 위해서 몇 번의 방향전환을 해야하는지 출력하시오.

예제 입력 1

2 3

예제 출력 1

2

예제 입력 2

5 3

예제 출력 2

5

예제 입력 3

4 10

예제 출력 3

6
W3sicHJvYmxlbV9pZCI6IjMyMDgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJjMzBcdWFjZTBcdWQ1MDggXHVjNTYwXHViYzhjXHViODA4IiwiZGVzY3JpcHRpb24iOiI8cD5cdWM1NjBcdWJjOGNcdWI4MDhcdWIyOTQgXHViYzMwXHVhYzAwIFx1YWNlMFx1ZDUwNFx1YjJlNCZuYnNwOzxcL3A+XHJcblxyXG48cD5cdWM1NjBcdWJjOGNcdWI4MDggXHVjNTVlXHVjNWQwXHViMjk0Jm5ic3A7TVx1YWMxY1x1Yzc1OCBcdWQ1ODlcdWFjZmMgTlx1YWMxY1x1Yzc1OCBcdWM1ZjRcdWM3M2NcdWI4NWMgXHVjNzc0XHViOGU4XHVjNWI0XHVjOWM0IFx1YWNmM1x1YzVkMCBcdWNkMDhcdWNmNWNcdWI4MWJcdWM3NzQgXHViMTkzXHVjNWVjXHVjODM4IFx1Yzc4OFx1YjJlNC48XC9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c3BhY2UgY2hhcmFjdGVyLiBNIGlzIG51bWJlciBvZiByb3dzIGFuZCBOIGlzIG51bWJlciBvZiBjb2x1bW5zLiZuYnNwOzxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPlRoZSBmaXJzdCBhbmQgb25seSBsaW5lIG9mIG91dHB1dCBzaG91bGQgY29udGFpbiB0aGUgbnVtYmVyIG9mIHR1cm5zIGEgd29ybSBuZWVkcyB0byBtYWtlIHVudGlsIGl0IGVhdHMgdGhlIHdob2xlIGNob2NvbGF0ZS48XC9wPlxyXG4iLCJoaW50IjoiIiwib3JpZ2luYWwiOiIxIiwicHJvYmxlbV9sYW5nX2NvZGUiOiJcdWM2MDFcdWM1YjQifV0=

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2004 > Regional Competition - Seniors 1번

  • 문제를 번역한 사람: baek1134
  • 잘못된 데이터를 찾은 사람: joonas