Logo
(追記) (追記ここまで)

13750번 - Zigzag 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB2101409367.391%

문제

A sequence of integers is said to Zigzag if adjacent elements alternate between strictly increasing and strictly decreasing. Note that the sequence may start by either increasing or decreasing. Given a sequence of integers, determine the length of the longest subsequence that Zigzags. For example, consider this sequence:

1 2 3 4 2

There are several Zigzagging subsequences of length 3:

1 3 2 1 4 2 2 3 2 2 4 2 3 4 2

But there are none of length greater than 3, so the answer is 3.

입력

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The first line of input contains an integer n (1 ≤ n ≤ 1,000,000) which is the number of integers in the list. Each of the following n lines will have an integer k (1 ≤ k ≤ 1,000,000)

출력

Output a single integer, which is the length of the longest Zigzagging subsequence of the input list.

제한

예제 입력 1

5
1
2
3
4
2

예제 출력 1

3

예제 입력 2

6
1
1
1
1
1
1

예제 출력 2

1

힌트

출처

ICPC > Regionals > North America > Southeast USA Regional > 2016 Southeast USA Regional Programming Contest > Division 1 K번

ICPC > Regionals > North America > Southeast USA Regional > 2016 Southeast USA Regional Programming Contest > Division 2 K번

ICPC > Regionals > North America > Pacific Northwest Regional > 2016 Pacific Northwest Region Programming Contest > Division 2 Y번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /