시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 81 68 55 84.615%

문제

애벌레는 배가 고프다 

애벌레 앞에는 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+XHJcblxyXG48cD5cdWM1NjBcdWJjOGNcdWI4MDggXHVjNTVlXHVjNWQwXHViMjk0Jm5ic3A7TVx1YWMxY1x1Yzc1OCBcdWQ1ODlcdWFjZmMgTlx1YWMxY1x1Yzc1OCBcdWM1ZjRcdWM3M2NcdWI4NWMgXHVjNzc0XHViOGU4XHVjNWI0XHVjOWM0IFx1YWNmM1x1YzVkMCBcdWNkMDhcdWNmNWNcdWI4MWJcdWM3NzQgXHViMTkzXHVjNWVjXHVjODM4IFx1Yzc4OFx1YjJlNC48X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cGFjZSBjaGFyYWN0ZXIuIE0gaXMgbnVtYmVyIG9mIHJvd3MgYW5kIE4gaXMgbnVtYmVyIG9mIGNvbHVtbnMuJm5ic3A7PFwvcD5cclxuIiwib3V0cHV0IjoiPHA+VGhlIGZpcnN0IGFuZCBvbmx5IGxpbmUgb2Ygb3V0cHV0IHNob3VsZCBjb250YWluIHRoZSBudW1iZXIgb2YgdHVybnMgYSB3b3JtIG5lZWRzIHRvIG1ha2UgdW50aWwgaXQgZWF0cyB0aGUgd2hvbGUgY2hvY29sYXRlLjxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

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

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