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

28162번 - One, Two, Three 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB64191636.364%

문제

You are given a sequence of length $N$: $A_0, A_1, \ldots, A_{N-1}$. It consists of only three kinds of integers: 1,ドル 2, 3$.

A tuple of indices $(i, j, k)$ is good if 0ドル \le i < j < k < N$ and it satisfies one of the two following conditions: either $A_i = 1, ,円 A_j = 2, ,円 A_k = 3$ or $A_i = 3, ,円 A_j = 2, ,円 A_k = 1$.

Your goal is find disjoint good tuples, as many of them as possible. A group of tuples is disjoint if no index is present in more than one tuple.

Find the maximum number of disjoint good tuples and print each tuple.

입력

The first line contains an integer $N,ドル the length of the given sequence (1ドル \le N \le 600,000円$).

The next line contains $N$ integers: $A_0, A_1, \ldots, A_{N-1}$ (1ドル \le A_i \le 3$).

출력

On the first line, print an integer $M,ドル the maximum number of disjoint good tuples.

On the next $M$ lines, print the tuples themselves. Each of these lines must contains three integers $i, j, k$ (0ドル \le i < j < k < N$) that describes a good tuple. All the printed tuples must be disjoint. If there are several solutions, print any one of them.

제한

예제 입력 1

6
3 1 2 2 3 1

예제 출력 1

2
1 2 4
0 3 5

예제 입력 2

6
2 1 3 1 3 2

예제 출력 2

0

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 2: GP of ainta C번

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

출처

대학교 대회

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

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