CF1552B.Running for Gold

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Olympic Games have just started and Federico is eager to watch the marathon race.

There will be nn athletes, numbered from 11 to nn, competing in the marathon, and all of them have taken part in 55 important marathons, numbered from 11 to 55, in the past. For each 1≤i≤n1\le i\le n and 1≤j≤51\le j\le 5, Federico remembers that athlete ii ranked ri,jr_{i,j}-th in marathon jj (e.g., r2,4=3r_{2,4}=3 means that athlete 22 was third in marathon 44).

Federico considers athlete xx superior to athlete yy if athlete xx ranked better than athlete yy in at least 33 past marathons, i.e., rx,j<ry,jr_{x,j} \lt r_{y,j} for at least 33 distinct values of jj.

Federico believes that an athlete is likely to get the gold medal at the Olympics if he is superior to all other athletes.

Find any athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes), or determine that there is no such athlete.

奥运会刚刚开始,费德里科急切地想要观看马拉松比赛。

将有 nn 名运动员参加马拉松比赛,编号从 11 到 nn;他们每个人都曾参加过过去 5 场重要的马拉松比赛(编号从 11 到 55)。对于每个 1≤i≤n1\le i\le n 和 1≤j≤51\le j\le 5,费德里科记得运动员 ii 在第 jj 场马拉松比赛中获得了第 ri,jr_{i,j} 名(例如,r2,4=3r_{2,4}=3 表示运动员 22 在第 44 场马拉松比赛中获得第三名)。

费德里科认为运动员 xx 优于运动员 yy,当且仅当运动员 xx 在至少 33 场过去的马拉松比赛中排名高于运动员 yy,即满足 rx,j<ry,jr_{x,j} \lt r_{y,j} 的不同 jj 值的个数至少为 33。

费德里科相信:若一名运动员优于所有其他运动员,则他极有可能在奥运会上夺得金牌。

请找出任意一名极有可能夺得金牌的运动员(即优于所有其他运动员的运动员),或判定不存在这样的运动员。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Then tt test cases follow.

The first line of each test case contains a single integer nn (1≤n≤50 0001\le n\le 50\,000) — the number of athletes.

Then nn lines follow, each describing the ranking positions of one athlete.

The ii-th of these lines contains the 55 integers ri,1, ri,2, ri,3, ri,4, ri,5r_{i,1},\,r_{i,2},\,r_{i,3},\,r_{i,4},\, r_{i,5} (1≤ri,j≤50 0001\le r_{i,j}\le 50\,000) — the ranking positions of athlete ii in the past 55 marathons. It is guaranteed that, in each of the 55 past marathons, the nn athletes have distinct ranking positions, i.e., for each 1≤j≤51\le j\le 5, the nn values r1,j, r2,j, …, rn,jr_{1,j},\, r_{2, j},\, \dots,\, r_{n, j} are distinct.

It is guaranteed that the sum of nn over all test cases does not exceed 50 00050\,000.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤50 0001\le n\le 50\,000),表示运动员的数量。

接下来是 nn 行,每行描述一名运动员的排名情况。

其中第 ii 行包含 55 个整数 ri,1, ri,2, ri,3, ri,4, ri,5r_{i,1},\,r_{i,2},\,r_{i,3},\,r_{i,4},\, r_{i,5}(1≤ri,j≤50 0001\le r_{i,j}\le 50\,000),分别表示运动员 ii 在过去 55 场马拉松比赛中的排名。保证在每一场过去的马拉松比赛中,这 nn 名运动员的排名互不相同;即对每个 1≤j≤51\le j\le 5,nn 个值 r1,j, r2,j, …, rn,jr_{1,j},\, r_{2, j},\, \dots,\, r_{n, j} 互不相同。

保证所有测试用例的 nn 值之和不超过 50 00050\,000。

输出格式

For each test case, print a single integer — the number of an athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes). If there are no such athletes, print −1-1. If there is more than such one athlete, print any of them.

对于每个测试用例,输出一个整数——即可能获得金牌的运动员编号(即优于所有其他运动员的运动员)。若不存在这样的运动员,则输出 −1-1;若存在多个这样的运动员,则输出其中任意一个即可。

输入输出样例

  • 输入#1

    4
    1
    50000 1 50000 50000 50000
    3
    10 10 20 30 30
    20 20 30 10 10
    30 30 10 20 20
    3
    1 1 1 1 1
    2 2 2 2 2
    3 3 3 3 3
    6
    9 5 3 7 1
    7 4 1 6 8
    5 6 7 3 2
    6 7 8 8 6
    4 2 2 4 5
    8 3 6 9 4

    输出#1

    1
    -1
    1
    5

说明/提示

Explanation of the first test case: There is only one athlete, therefore he is superior to everyone else (since there is no one else), and thus he is likely to get the gold medal.

Explanation of the second test case: There are n=3n=3 athletes.

  • Athlete 11 is superior to athlete 22. Indeed athlete 11 ranks better than athlete 22 in the marathons 11, 22 and 33.
  • Athlete 22 is superior to athlete 33. Indeed athlete 22 ranks better than athlete 33 in the marathons 11, 22, 44 and 55.
  • Athlete 33 is superior to athlete 11. Indeed athlete 33 ranks better than athlete 11 in the marathons 33, 44 and 55.

Explanation of the third test case: There are n=3n=3 athletes.

  • Athlete 11 is superior to athletes 22 and 33. Since he is superior to all other athletes, he is likely to get the gold medal.
  • Athlete 22 is superior to athlete 33.
  • Athlete 33 is not superior to any other athlete.

Explanation of the fourth test case: There are n=6n=6 athletes.

  • Athlete 11 is superior to athletes 33, 44, 66.
  • Athlete 22 is superior to athletes 11, 44, 66.
  • Athlete 33 is superior to athletes 22, 44, 66.
  • Athlete 44 is not superior to any other athlete.
  • Athlete 55 is superior to athletes 11, 22, 33, 44, 66. Since he is superior to all other athletes, he is likely to get the gold medal.
  • Athlete 66 is only superior to athlete 44.

第一个测试用例说明:只有一名运动员,因此他优于所有其他人(因为实际上并不存在其他任何人),所以他很可能获得金牌。

第二个测试用例说明:共有 n=3n=3 名运动员。

  • 运动员 11 优于运动员 22。事实上,运动员 11 在马拉松 11、22 和 33 中的排名均优于运动员 22。
  • 运动员 22 优于运动员 33。事实上,运动员 22 在马拉松 11、22、44 和 55 中的排名均优于运动员 33。
  • 运动员 33 优于运动员 11。事实上,运动员 33 在马拉松 33、44 和 55 中的排名均优于运动员 11。

第三个测试用例说明:共有 n=3n=3 名运动员。

  • 运动员 11 优于运动员 22 和 33。由于他优于所有其他运动员,所以他很可能获得金牌。
  • 运动员 22 优于运动员 33。
  • 运动员 33 不优于任何其他运动员。

第四个测试用例说明:共有 n=6n=6 名运动员。

  • 运动员 11 优于运动员 33、44、66。
  • 运动员 22 优于运动员 11、44、66。
  • 运动员 33 优于运动员 22、44、66。
  • 运动员 44 不优于任何其他运动员。
  • 运动员 55 优于运动员 11、22、33、44、66。由于他优于所有其他运动员,所以他很可能获得金牌。
  • 运动员 66 仅优于运动员 44。

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

首页