Mashup

시간 제한2초메모리 제한256 MB

요약
N개의 대회를 순열로 재배열해 난이도가 비증가하는 대회를 만드는 경우의 수를 2로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

유형
조합론, 수학, 그리디
정답자
아직 제출이 없습니다

문제

Nike Nirzayanov, the founder of the popular competitive typing platform SpeedForces, has recently added a new feature allowing users to create random mashups of past contests.

A contest on SpeedForces consists of NN implementation problems, each with a difficulty rating among 800,900,1000,1100,1200\\{800,900,1000,1100,1200\\}. The NN problems in a single contest are always arranged in nondecreasing order of difficulty and assigned problem slots from 11 to NN in order.

Busy Beaver is testing out the new feature. He first specifies NN past contests, where the ii-th contest he specifies has a_ija\_{ij} problems of difficulty 800+100(j−1)800+100(j-1) for each 1≤j≤51 \le j \le 5, where ∑_j=15a_ij=N\sum\_{j=1}^5 a\_{ij} = N.

The feature will select a random permutation p_1,p_2,…,p_Np\_1,p\_2,\dots,p\_N of 1,2,…,N1,2,\dots,N and generate for Busy Beaver a contest where the ii-th problem is the ii-th problem in the p_ip\_i-th contest he specified.

Busy Beaver wonders: How many such permutations will result in a contest with reverse difficulty order (i.e., the problem difficulties are in nonincreasing order)? For some reason, he only wants the answer modulo 2.

입력

Each test contains multiple test cases. The first line contains the number of test cases TT (1≤T≤1041 \leq T \leq 10^4). The description of the test cases follows.

The first line of each test case contains the integer NN (1≤N≤2⋅1051 \le N \le 2 \cdot 10^5) --- the number of past contests and problems.

The next NN lines of each test case each contain 55 integers a_i1,a_i2,a_i3,a_i4,a_i5a\_{i1},a\_{i2},a\_{i3},a\_{i4},a\_{i5} (a_ij≥0a\_{ij} \ge 0 and ∑_j=15a_ij=N\sum\_{j=1}^5 a\_{ij} = N).

It is guaranteed that the sum of NN across all test cases is no more than 2⋅1052 \cdot 10^5.

출력

For each test case, output a single integer, the number of such permutations modulo 22.

힌트

In the first test case, the N=3N = 3 past contests have the following problem difficulties:

  • Contest 11: 800,900,900800, 900, 900.
  • Contest 22: 900,900,900900, 900, 900.
  • Contest 33: 1000,1000,10001000, 1000, 1000.

There are 22 permutations pp that result in a reverse difficulty order contest: p=\[3,1,2]p = \[3, 1, 2] and p=\[3,2,1]p = \[3, 2, 1]. Therefore, the answer is 2 mod 2=02 \bmod 2 = 0.

In the second test case, the N=4N = 4 past contests have the following problem difficulties:

  • Contest 11: 800,800,800,800800, 800, 800, 800.
  • Contest 22: 800,900,900,900800, 900, 900, 900.
  • Contest 33: 900,900,900,1000900, 900, 900, 1000.
  • Contest 44: 900,900,1000,1000900, 900, 1000, 1000.

There are 33 permutations pp that result in a reverse difficulty order contest: p=\[3,4,2,1]p = \[3, 4, 2, 1], p=\[4,2,3,1]p = \[4, 2, 3, 1], and p=\[4,3,2,1]p = \[4, 3, 2, 1]. Therefore, the answer is 3 mod 2=13 \bmod 2 = 1.

In the third test case, the only permutation p=\[1]p = \[1] generates a reverse difficulty order contest, so the answer is 1 mod 2=11 \bmod 2 = 1.

예제1

  1. 예제 1

    입력
    3
    3
    1 2 0 0 0
    0 3 0 0 0
    0 0 3 0 0
    4
    4 0 0 0 0
    1 3 0 0 0
    0 3 1 0 0
    0 2 2 0 0
    1
    1 0 0 0 0
    
    예상 출력
    0
    1
    1