CF1491I.Ruler Of The Zoo

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

After realizing that Zookeeper is just a duck, the animals have overthrown Zookeeper. They now have to decide a new ruler among themselves through a fighting tournament of the following format:

Initially, animal 00 is king, while everyone else queues up with animal 11 at the front of the queue and animal n−1n-1 at the back. The animal at the front of the queue will challenge the king to a fight, and the animal with greater strength will win the fight. The winner will become king, while the loser joins the back of the queue.

An animal who wins 33 times consecutively will be crowned ruler for the whole zoo. The strength of each animal depends on how many consecutive fights he won. Animal ii has strength AiA_i with 00 consecutive win, BiB_i with 11 consecutive win, and CiC_i with 22 consecutive wins. Initially, everyone has 00 consecutive win.

For all animals, Ai>BiA_i \gt B_i and Ci>BiC_i \gt B_i. Also, the values of AiA_i, BiB_i, CiC_i are distinct (all 3n3n values are pairwise different).

In other words, an animal who is not a king has strength AiA_i. A king usually has a strength of BiB_i or CiC_i. The exception is on the first turn, the first king (animal 00) has strength AiA_i.

Who is the new ruler, and after how many fights? Or will it end up that animals fight forever with no one ending up as ruler?

在意识到动物园管理员(Zookeeper)不过是一只鸭子后,动物们推翻了它。现在,它们需要通过一场如下形式的格斗锦标赛,从自己中间选出一位新统治者:

初始时,动物 00 是国王,其余所有动物排成一列,动物 11 位于队首,动物 n−1n-1 位于队尾。队首的动物将向国王发起挑战,双方进行格斗;力量值更大的动物获胜。胜者成为新国王,败者则排到队尾。

若某只动物连续获胜三次,它将被加冕为整个动物园的统治者。每只动物的力量值取决于其已连续获胜的次数:动物 ii 在拥有 00 次连续胜利时力量为 AiA_i,拥有 11 次连续胜利时力量为 BiB_i,拥有 22 次连续胜利时力量为 CiC_i。初始时,所有动物的连续获胜次数均为 00。

对所有动物 ii,均满足 Ai>BiA_i > B_i 且 Ci>BiC_i > B_i。此外,所有 AiA_i、BiB_i、CiC_i 的取值互不相同(即全部 3n3n 个数值两两不同)。

换言之,非国王的动物力量恒为 AiA_i;国王的力量通常为 BiB_i 或 CiC_i;唯一的例外是第一回合——首位国王(动物 00)此时力量为 A0A_0。

谁将成为新统治者?在第几场格斗之后?或者,动物们是否会永远格斗下去,而无人能最终加冕为统治者?

输入格式

The first line contains one integer nn (4≤n≤60004 \leq n \leq 6000) — number of the animals.

ii-th of the next nn lines contains 33 integers AiA_i, BiB_i and CiC_i (0≤Ai,Bi,Ci≤1090 \leq A_i, B_i, C_i \leq 10^9).

It is guaranteed that Ai>BiA_i \gt B_i and Ci>BiC_i \gt B_i, and that all values of AiA_i, BiB_i and CiC_i are distinct.

第一行包含一个整数 nn(4≤n≤60004 \leq n \leq 6000)—— 动物的数量。

接下来的 nn 行中,第 ii 行包含三个整数 AiA_i、BiB_i 和 CiC_i(0≤Ai,Bi,Ci≤1090 \leq A_i, B_i, C_i \leq 10^9)。

保证 Ai>BiA_i > B_i 且 Ci>BiC_i > B_i,并且所有 AiA_i、BiB_i、CiC_i 的值互不相同。

输出格式

Output two integers in a single line. The first is the index of the animal that will become ruler, and the second is the number of fights passed until some animal becomes the ruler.

If the animals will fight for infinitely long, output -1 -1 instead.

在一行中输出两个整数。第一个是将成为统治者的动物的编号,第二个是直到某只动物成为统治者所经历的战斗次数。

如果动物们将无限期地持续战斗,则输出 -1 -1。

输入输出样例

  • 输入#1

    4
    5 1 2
    10 8 11
    9 0 3
    7 4 6

    输出#1

    -1 -1
  • 输入#2

    5
    11 7 12
    8 6 14
    2 1 10
    13 0 9
    5 3 4

    输出#2

    1 7

说明/提示

The following describes the sequence of events for the second sample. Note that in fight 11, the king (animal 00) has strength A0A_0. The tournament ends at fight 77 as animal 11 wins fight 55, 66 and 77.

以下是第二个样例的事件序列描述。注意:在第 11 场战斗中,国王(动物 00)的力量值为 A0A_0。锦标赛在第 77 场战斗结束,因为动物 11 连续赢得了第 55、66 和 77 场战斗。

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

首页