아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Make a Loop

시간 제한2초메모리 제한1024 MB

요약
반지름이 각각 다른 사분원 트랙 여러 개를 모두 매끄럽게 이어 붙여 하나의 닫힌 고리를 만들 수 있는지 판정한다.
난이도

보통10점 중 6점

유형
기하, 완전 탐색, 백트래킹
정답자
아직 제출이 없습니다

문제

Taro is playing with a set of toy rail tracks. All of the tracks are arc-shaped with a right central angle (an angle of 90 degrees), but with many different radii. He is trying to construct a single loop using all of them. Here, a set of tracks is said to form a single loop when both ends of all the tracks are smoothly joined to some other track, and all the tracks are connected to all the other tracks directly or indirectly. Please tell Taro whether he can ever achieve that or not.

Tracks may be joined in an arbitrary order, but their directions are restricted by the directions of adjacent tracks, as they must be joined smoothly. For example, if you place a track so that a train enters eastward and turns 90 degrees northward, you must place the next track so that the train enters northward and turns 90 degrees to either east or west (Figure F.1). Tracks may cross or even overlap each other as elevated construction is possible.

Figure F.1. Example of smoothly joining tracks

입력

The input consists of a single test case in the following format.

nn

r_1r\_1 ⋯\cdots r_nr\_n

nn represents the number of tracks, which is an even integer satisfying 4≤n≤1004 ≤ n ≤ 100. Each r_ir\_i represents the radius of the ii-th track, which is an integer satisfying 1≤r_i≤100001 ≤ r\_i ≤ 10000.

출력

If it is possible to construct a single loop using all of the tracks, print Yes; otherwise, print No.

힌트

Possible loops for the sample inputs 1, 2, and 4 are depicted in the following figures.

(a) Sample 1(b) Sample 2(c) Sample 4

Figure F.2. Possible loops for the sample inputs

예제4

  1. 예제 1

    입력
    4
    1 1 1 1
    
    예상 출력
    Yes
    
  2. 예제 2

    입력
    6
    1 3 1 3 1 3
    
    예상 출력
    Yes
    
  3. 예제 3

    입력
    6
    2 2 1 1 1 1
    
    예상 출력
    No
    
  4. 예제 4

    입력
    8
    99 98 15 10 10 5 2 1
    
    예상 출력
    Yes