CF1704D.Magical Array

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Eric has an array bb of length mm, then he generates nn additional arrays c1,c2,…,cnc_1, c_2, \dots, c_n, each of length mm, from the array bb, by the following way:

Initially, ci=bc_i = b for every 1≤i≤n1 \le i \le n. Eric secretly chooses an integer kk (1≤k≤n)(1 \le k \le n) and chooses ckc_k to be the special array.

There are two operations that Eric can perform on an array ctc_t:

  • Operation 1: Choose two integers ii and jj (2≤i<j≤m−12 \leq i \lt j \leq m-1), subtract 11 from both ct[i]c_t[i] and ct[j]c_t[j], and add 11 to both ct[i−1]c_t[i-1] and ct[j+1]c_t[j+1]. That operation can only be used on a non-special array, that is when t≠kt \neq k.;

  • Operation 2: Choose two integers ii and jj (2≤i<j≤m−22 \leq i \lt j \leq m-2), subtract 11 from both ct[i]c_t[i] and ct[j]c_t[j], and add 11 to both ct[i−1]c_t[i-1] and ct[j+2]c_t[j+2]. That operation can only be used on a special array, that is when t=kt = k.

    Note that Eric can't perform an operation if any element of the array will become less than 00 after that operation.

Now, Eric does the following:

  • For every non-special array cic_i (i≠ki \neq k), Eric uses only operation 1 on it at least once.
  • For the special array ckc_k, Eric uses only operation 2 on it at least once.

Lastly, Eric discards the array bb.

For given arrays c1,c2,…,cnc_1, c_2, \dots, c_n, your task is to find out the special array, i.e. the value kk. Also, you need to find the number of times of operation 22 was used on it.

Eric 有一个长度为 mm 的数组 bb,然后他基于数组 bb 生成了 nn 个额外的数组 c1,c2,…,cnc_1, c_2, \dots, c_n,每个长度均为 mm,具体方式如下:

初始时,对每个 1≤i≤n1 \le i \le n,令 ci=bc_i = b。Eric 秘密选择一个整数 kk(满足 1≤k≤n1 \le k \le n),并将 ckc_k 设为特殊数组。

Eric 可以对任意数组 ctc_t 执行以下两种操作之一:

  • 操作 1:选择两个整数 ii 和 jj(满足 2≤i<j≤m−12 \leq i \lt j \leq m-1),将 ct[i]c_t[i] 和 ct[j]c_t[j] 各减 11,同时将 ct[i−1]c_t[i-1] 和 ct[j+1]c_t[j+1] 各加 11。该操作仅可用于非特殊数组,即当 t≠kt \neq k 时;
  • 操作 2:选择两个整数 ii 和 jj(满足 2≤i<j≤m−22 \leq i \lt j \leq m-2),将 ct[i]c_t[i] 和 ct[j]c_t[j] 各减 11,同时将 ct[i−1]c_t[i-1] 和 ct[j+2]c_t[j+2] 各加 11。该操作仅可用于特殊数组,即当 t=kt = k 时。

注意:若某次操作会导致数组中任一元素变为负数,则 Eric 不得执行该操作。

接下来,Eric 执行如下步骤:

  • 对每个非特殊数组 cic_i(即 i≠ki \neq k),Eric 仅使用操作 1,且至少执行一次;
  • 对特殊数组 ckc_k,Eric 仅使用操作 2,且至少执行一次。

最后,Eric 丢弃原始数组 bb。

现给定数组 c1,c2,…,cnc_1, c_2, \dots, c_n,你的任务是找出特殊数组,即确定 kk 的值;同时,还需确定在该特殊数组 ckc_k 上执行操作 2 的次数。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers nn and mm (3≤n≤1053 \leq n \leq 10^5, 7≤m≤3⋅1057 \leq m \leq 3 \cdot 10^5) — the number of arrays given to you, and the length of each array.

The next nn lines contains mm integers each, ci,1,ci,2,…,ci,mc_{i,1}, c_{i,2}, \dots , c_{i,m}.

It is guaranteed that each element of the discarded array bb is in the range [0,106][0,10^6], and therefore 0≤ci,j≤3⋅10110 \leq c_{i,j} \leq 3 \cdot 10^{11} for all possible pairs of (i,j)(i,j).

It is guaranteed that the sum of n⋅mn \cdot m over all test cases does not exceed 10610^6.

It is guaranteed that the input is generated according to the procedure above.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(3≤n≤1053 \leq n \leq 10^5,7≤m≤3⋅1057 \leq m \leq 3 \cdot 10^5)—— 分别表示提供给你的数组个数,以及每个数组的长度。

接下来的 nn 行,每行包含 mm 个整数:ci,1,ci,2,…,ci,mc_{i,1}, c_{i,2}, \dots , c_{i,m}。

保证被丢弃的数组 bb 的每个元素均在区间 [0,106][0,10^6] 内,因此对所有可能的 (i,j)(i,j) 对均有 0≤ci,j≤3⋅10110 \leq c_{i,j} \leq 3 \cdot 10^{11}。

保证所有测试用例中 n⋅mn \cdot m 的总和不超过 10610^6。

保证输入是严格按照上述过程生成的。

输出格式

For each test case, output one line containing two integers — the index of the special array, and the number of times that Operation 2 was performed on it. It can be shown that under the constraints given in the problem, this value is unique and won't exceed 101810^{18}, so you can represent it as a 6464-bit integer. It can also be shown that the index of the special array is uniquely determined.

In this problem, hacks are disabled.

对于每个测试用例,输出一行,包含两个整数——特殊数组的下标,以及对该特殊数组执行操作 2 的次数。在本题给定的约束条件下,可以证明该数值是唯一的,且不会超过 101810^{18},因此你可以使用 64 位整数来表示它。同时也可以证明,特殊数组的下标是唯一确定的。

本题中禁止进行 Hack。

输入输出样例

  • 输入#1

    7
    3 9
    0 1 2 0 0 2 1 1 0
    0 1 1 1 2 0 0 2 0
    0 1 2 0 0 1 2 1 0
    3 7
    25 15 20 15 25 20 20
    26 14 20 14 26 20 20
    25 15 20 15 20 20 25
    3 9
    25 15 20 15 25 20 20 20 20
    26 14 20 14 26 20 20 20 20
    25 15 20 15 25 15 20 20 25
    3 11
    25 15 20 15 25 20 20 20 20 20 20
    26 14 20 14 26 20 20 20 20 20 20
    25 15 20 15 25 20 15 20 20 20 25
    3 13
    25 15 20 15 25 20 20 20 20 20 20 20 20
    26 14 20 14 26 20 20 20 20 20 20 20 20
    25 15 20 15 25 20 20 15 20 20 20 20 25
    3 15
    25 15 20 15 25 20 20 20 20 20 20 20 20 20 20
    26 14 20 14 26 20 20 20 20 20 20 20 20 20 20
    25 15 20 15 25 20 20 20 15 20 20 20 20 20 25
    3 9
    909459 479492 676924 224197 162866 164495 193268 742456 728277
    948845 455424 731850 327890 304150 237351 251763 225845 798316
    975446 401170 792914 272263 300770 242037 236619 334316 725899

    输出#1

    3 1
    3 10
    3 15
    3 20
    3 25
    3 30
    1 1378716

说明/提示

In the first test case, the secret array bb is [0,1,1,1,1,1,1,1,0][0, 1, 1, 1, 1, 1, 1, 1, 0]. Array c1c_1 and array c2c_2 are generated by using operation 1. Array c3c_3 is generated by using operation 2.

For Array c1c_1,you can choose i=4i=4 and j=5j=5 perform Operation 1 one time to generate it. For Array c2c_2, you can choose i=6i=6 and j=7j=7 perform Operation 1 one time to generate it. For Array c3c_3,you can choose i=4i=4 and j=5j=5 perform Operation 2 one time to generate it.

In the second test case, the secret array bb is [20,20,20,20,20,20,20][20, 20, 20, 20, 20, 20, 20]. You can also find that array c1c_1 and array c2c_2 are generated by using Operation 1. Array c3c_3 is generated by using Operation 2.

In the third test case, the secret array bb is [20,20,20,20,20,20,20,20,20][20, 20, 20, 20, 20, 20, 20, 20, 20]. You can also find that array c1c_1 and array c2c_2 are generated by using Operation 1. Array c3c_3 is generated by using Operation 2.

在第一个测试用例中,秘密数组 bb 为 [0,1,1,1,1,1,1,1,0][0, 1, 1, 1, 1, 1, 1, 1, 0]。数组 c1c_1 和数组 c2c_2 是通过使用操作 1 生成的;数组 c3c_3 是通过使用操作 2 生成的。

对于数组 c1c_1,可选择 i=4i=4 和 j=5j=5,执行一次操作 1 来生成它;对于数组 c2c_2,可选择 i=6i=6 和 j=7j=7,执行一次操作 1 来生成它;对于数组 c3c_3,可选择 i=4i=4 和 j=5j=5,执行一次操作 2 来生成它。

在第二个测试用例中,秘密数组 bb 为 [20,20,20,20,20,20,20][20, 20, 20, 20, 20, 20, 20]。同样可以发现,数组 c1c_1 和数组 c2c_2 是通过使用操作 1 生成的,而数组 c3c_3 是通过使用操作 2 生成的。

在第三个测试用例中,秘密数组 bb 为 [20,20,20,20,20,20,20,20,20][20, 20, 20, 20, 20, 20, 20, 20, 20]。同样可以发现,数组 c1c_1 和数组 c2c_2 是通过使用操作 1 生成的,而数组 c3c_3 是通过使用操作 2 生成的。

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

首页