CF1704D.Magical Array
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Eric has an array b of length m , then he generates n additional arrays c1,c2,…,cn , each of length m , from the array b , by the following way:
Initially, ci=b for every 1≤i≤n . Eric secretly chooses an integer k (1≤k≤n) and chooses ck to be the special array.
There are two operations that Eric can perform on an array ct :
- Operation 1: Choose two integers i and j ( 2≤i<j≤m−1 ), subtract 1 from both ct[i] and ct[j] , and add 1 to both ct[i−1] and ct[j+1] . That operation can only be used on a non-special array, that is when t=k .;
- Operation 2: Choose two integers i and j ( 2≤i<j≤m−2 ), subtract 1 from both ct[i] and ct[j] , and add 1 to both ct[i−1] and ct[j+2] . That operation can only be used on a special array, that is when t=k .Note that Eric can't perform an operation if any element of the array will become less than 0 after that operation.
Now, Eric does the following:
- For every non-special array ci ( i=k ), Eric uses only operation 1 on it at least once.
- For the special array ck , Eric uses only operation 2 on it at least once.
Lastly, Eric discards the array b .
For given arrays c1,c2,…,cn , your task is to find out the special array, i.e. the value k . Also, you need to find the number of times of operation 2 was used on it.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. Description of test cases follows.
The first line of each test case contains two integers n and m ( 3≤n≤105 , 7≤m≤3⋅105 ) — the number of arrays given to you, and the length of each array.
The next n lines contains m integers each, ci,1,ci,2,…,ci,m .
It is guaranteed that each element of the discarded array b is in the range [0,106] , and therefore 0≤ci,j≤3⋅1011 for all possible pairs of (i,j) .
It is guaranteed that the sum of n⋅m over all test cases does not exceed 106 .
It is guaranteed that the input is generated according to the procedure above.
输出格式
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 1018 , so you can represent it as a 64 -bit integer. It can also be shown that the index of the special array is uniquely determined.
In this problem, hacks are disabled.
输入输出样例
输入#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 b is [0,1,1,1,1,1,1,1,0] . Array c1 and array c2 are generated by using operation 1. Array c3 is generated by using operation 2.
For Array c1 ,you can choose i=4 and j=5 perform Operation 1 one time to generate it. For Array c2 , you can choose i=6 and j=7 perform Operation 1 one time to generate it. For Array c3 ,you can choose i=4 and j=5 perform Operation 2 one time to generate it.
In the second test case, the secret array b is [20,20,20,20,20,20,20] . You can also find that array c1 and array c2 are generated by using Operation 1. Array c3 is generated by using Operation 2.
In the third test case, the secret array b is [20,20,20,20,20,20,20,20,20] . You can also find that array c1 and array c2 are generated by using Operation 1. Array c3 is generated by using Operation 2.