問題一覧 > 通常問題

No.360 増加門松列

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 128 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 161
作問者 : koyumeishi
お気に入りにしたユーザー ProblemId : 1067 / 自分の提出
問題文最終更新日: 2026-06-25 02:49:40
Increasing Kadomatsu Sequence
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder 門松コンテスト (順位表) の他の問題:

Problem Statement

A Kadomatsu sequence is a sequence of $3$ elements $A_1, A_2, A_3$ that satisfies the following 2 conditions.

  • $A_1, A_2, A_3$ are all distinct
  • Among the $3$ elements, $A_2$ is the largest or $A_2$ is the smallest

When a sequence $A_1, A_2, A_3$ is a Kadomatsu sequence and $A_1 < A_3$, it is called an increasing Kadomatsu sequence.
Also, when all contiguous subsequences of length $3$ of a sequence $ A = A_1, A_2, ... , A_n $ of length $n$ are increasing Kadomatsu sequences, the sequence $A$ is called an increasing Kadomatsu sequence chain.
A contiguous subsequence of length $3$ means $A_i, A_{i+1}, A_{i+2}$ $(1 \leq i \leq n-2)$.

Koyumeishi is planning to hold a competitive programming contest themed on Kadomatsu sequences.
He has created $7$ problems in total, and since the theme is Kadomatsu sequences, he thought the order of the problems should also be related to Kadomatsu sequences.
Participants would be startled if very difficult problems came early on, so it seems good to arrange the problems so that their difficulties form an increasing Kadomatsu sequence chain.
Oh, but wait. Depending on the distribution of the problems' difficulties, it may be impossible to form an increasing Kadomatsu sequence chain... What a problem.

Given the difficulties of the 7 problems, determine whether they can be arranged in the order of an increasing Kadomatsu sequence chain.
Print "YES" if possible, and "NO" if impossible.

Input

$D_1$ $D_2$ $D_3$ $D_4$ $D_5$ $D_6$ $D_7$

The difficulties of the 7 problems are given separated by spaces.
The input values are integers satisfying $1 \leq D_k \leq 100$.

Output

Print "YES" if they can be arranged into an increasing Kadomatsu sequence chain, and "NO" if impossible.

Sample

Sample 1
Input
1 2 3 4 5 6 7
Output
YES

For example, arranging them as
1 3 2 5 4 7 6
gives an increasing Kadomatsu sequence chain.

Sample 2
Input
1 1 1 1 1 1 1
Output
NO

Unfortunately, they cannot be arranged into an increasing Kadomatsu sequence chain.

Sample 3
Input
1 2 2 3 3 4 5
Output
YES

2 1 3 2 4 3 5
is an increasing Kadomatsu sequence chain.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。