CF893A.Chess For Three

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.

So they play with each other according to following rules:

  • Alex and Bob play the first game, and Carl is spectating;
  • When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.

Alex, Bob and Carl play in such a way that there are no draws.

Today they have played n games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!

亚历克斯、鲍勃和卡尔即将参加一场团体国际象棋锦标赛。由于他们同属一支队伍,因此决定在锦标赛前刻苦训练。但训练存在一定困难,因为国际象棋是两人对弈的游戏,而非三人游戏。

于是他们按照以下规则相互对弈:

  • 第一局由亚历克斯与鲍勃对弈,卡尔观战;
  • 每局结束后,本局的负者成为下一局的观战者,而上一局的观战者则与本局的胜者对弈。

亚历克斯、鲍勃和卡尔的对弈均无平局。

今天他们共进行了 nn 局对弈,且对每局都记录了胜者。他们决定整理一份对弈日志,记录每局的胜者。但现在他们怀疑这份日志的内容是否正确,希望知道日志所描述的情形是否可能(即:在严格遵守上述规则的前提下,没有任何一局的胜者是当时正在观战的人)。请帮助他们验证!

输入格式

The first line contains one integer n (1 ≤ n ≤ 100) — the number of games Alex, Bob and Carl played.

Then n lines follow, describing the game log. i-th line contains one integer a__i (1 ≤ a__i ≤ 3) which is equal to 1 if Alex won i-th game, to 2 if Bob won i-th game and 3 if Carl won i-th game.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 表示 Alex、Bob 和 Carl 进行的比赛场数。

接下来是 nn 行,描述比赛记录。第 ii 行包含一个整数 aia_i(1≤ai≤31 \leq a_i \leq 3),其中若 Alex 赢得第 ii 场比赛,则 ai=1a_i = 1;若 Bob 赢得第 ii 场比赛,则 ai=2a_i = 2;若 Carl 赢得第 ii 场比赛,则 ai=3a_i = 3。

输出格式

Print YES if the situation described in the log was possible. Otherwise print NO.

如果日志中描述的情况是可能的,则输出 YES;否则输出 NO。

输入输出样例

  • 输入#1

    3
    1
    1
    2

    输出#1

    YES
  • 输入#2

    2
    1
    2

    输出#2

    NO

说明/提示

In the first example the possible situation is:

  1. Alex wins, Carl starts playing instead of Bob;
  2. Alex wins, Bob replaces Carl;
  3. Bob wins.

The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.

在第一个例子中,可能的情况是:

  1. Alex 获胜,Carl 代替 Bob 开始比赛;
  2. Alex 获胜,Bob 替换 Carl;
  3. Bob 获胜。

第二个例子中的情况是不可能的,因为 Bob 在第一局比赛中失利,因此他无法赢得第二局。

输入解题思路,AI测评打分。不知道怎么写?

首页