시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 60 23 23 48.936%

문제

원 모양으로 나열된 N개의 필드를 가진 게임판이 있다. 각 필드는 1~N까지 시계방향으로 숫자가 매겨져 있다. 몇개의 필드에는 장애물이 놓여져 있다.

아람이는 1에서 게임을 시작한다. Z번째 필드에 도착하는 것이 이 게임의 목표이다. 도착점은 K만큼씩 시계방향으로 이동해 도달해야 한다. 도착점으로 가는 길에 장애물이 있는 필드를 밟아서는 안된다.

예를들어 N=13, K=3 그리고 Z=9라고 했을 때 아람이는 1,4,7,10,13,3,6 그리고 9 의 필드를 지나게 된다. 도착점으로 가는 경로 중 장애물이 있는 필드가 하나라도 있으면 안 된다.

게임판의 정보가 주어졌을 때 도착점에 도착할 수 있는 가장 작은 K를 찾는 프로그램을 작성하시오.

입력

입력의 첫째 줄에는 N(2 ≤ N ≤ 1000), Z(2 ≤ Z), M(0 ≤ M ≤ N-2) 이 주어진다.

N은 필드의 수이고 Z는 도착해야하는 필드의 번호를 의미한다.

다음 M개의 줄에는 서로 다른 정수가 주어진다. 이 정수는 장애물이 있는 필드의 번호를 나타낸다.

1번과 Z번째 필드에는 장애물이 놓이지 않는다.

출력

출력의 첫 번째 줄에 위에서 정의되어진 K를 출력한다.

예제 입력 1

7 4 1
6

예제 출력 1

1

예제 입력 2

9 7 2
2 3

예제 출력 2

3

예제 입력 3

7 6 2
2 4

예제 출력 3

5
W3sicHJvYmxlbV9pZCI6IjMyNTgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWNlZjRcdWQzZWNcdWQyYjgiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzZkMCBcdWJhYThcdWM1OTFcdWM3M2NcdWI4NWMgXHViMDk4XHVjNWY0XHViNDFjIE5cdWFjMWNcdWM3NTggXHVkNTQ0XHViNGRjXHViOTdjIFx1YWMwMFx1YzljNCBcdWFjOGNcdWM3ODRcdWQzMTBcdWM3NzQgXHVjNzg4XHViMmU0LiBc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cD5Zb3VyIHRhc2sgaXMgdG8gd3JpdGUgYSBwcm9ncmFtIHRoYXQgZmluZHMgdGhlIHNtYWxsZXN0IHBvc3NpYmxlIG51bWJlciBLLjxcL3A+XHJcbiIsImlucHV0IjoiPHA+Rmlyc3QgbGluZSBvZiB0aGUgaW5wdXQgZmlsZSBjb25zaXN0cyBvZiBpbnRlZ2VycyBOLCBaIGFuZCBNLCAyICZsZTsgTiAmbGU7IDEwMDAsIDIgJmxlOyBaLCAwICZsZTsgTSAmbGU7IE4tMi48XC9wPlxyXG5cclxuPHA+TiByZXByZXNlbnRzIG51bWJlciBvZiBmaWVsZHMgb24gdGhlIGdhbWUtYm9hcmQgYW5kIFogaXMgYSBnaXZlbiBnb2FsLWZpZWxkLjxcL3A+XHJcblxyXG48cD5OZXh0IGxpbmUgY29uc2lzdHMgb2YgTSBkaWZmZXJlbnQgaW50ZWdlcnMgdGhhdCByZXByZXNlbnQgbWFya3Mgb2YgZmllbGRzIGhhdmluZyBhbiBvYnN0YWNsZS4gRmllbGRzIG1hcmtlZCAxIGFuZCBaIGRvIG5vdCBjb250YWluIGFuIG9ic3RhY2xlLiZuYnNwOzxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPlRoZSBmaXJzdCBhbmQgb25seSBsaW5lIG9mIHRoZSBvdXRwdXQgZmlsZSBzaG91bGQgY29udGFpbiByZXF1ZXN0ZWQgbnVtYmVyIEsgZGVmaW5lZCBhYm92ZS4mbmJzcDs8XC9wPlxyXG4iLCJoaW50IjoiIiwib3JpZ2luYWwiOiIxIiwicHJvYmxlbV9sYW5nX2NvZGUiOiJcdWM2MDFcdWM1YjQifV0=

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2002 > National Competition #1 - Juniors 1번

  • 문제를 번역한 사람: baek1134
  • 문제의 오타를 찾은 사람: logwns