#P5614. [MtOI2019] 膜Siyuan

    ID: 6318 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学2019洛谷原创O2优化枚举洛谷月赛

[MtOI2019] 膜Siyuan

Background

You are strong if you are strong, but Siyuan\mathsf S\mathsf{\color{red} iyuan} is stronger than you. ——Siyuan\mathsf S \mathsf{\color{red} iyuan}.

Recently, disangan233 found a game for OIers: Mo Siyuan\color{black} \mathsf S \mathsf{\color{red} iyuan}.

He was confused by “Truth IV” in it, so he came to you for help.

Problem Description

You are given 11 positive integer MM and nn (n5)(n\leq 5) positive-integer triples {ai,bi,ci}\{a_i,b_i,c_i\} (ai,bi,ciM2000)(a_i,b_i,c_i\leq M\leq 2000). Please find the number of all ordered positive-integer triples {x,y,z}\{x,y,z\} (x,y,zM)(x,y,z \leq M) that satisfy:

$$\forall i\leq n ,s.t.~|a_i-x|\oplus |b_i-y|\oplus |c_i-z| = 9$$

Here, \forall means “for all”, s.t.s.t. means “such that”, and ABCA \oplus B \oplus C is the XOR of A,B,CA,B,C.

In C++, A^B^C or A xor B xor C is exactly the value of ABCA \oplus B \oplus C.

A template is provided here:

if ((a ^ b ^ c) == 9) 
{
	Your code here...
}

For two ordered triples A,BA,B, if xAxBx_A \not =x_B or yAyBy_A \not =y_B or zAzBz_A \not =z_B, then AA and BB are considered different.

Input Format

There are n+1n+1 lines in total.

The first line contains 22 positive integers nn and MM.

In the next nn lines, the ii-th line contains 33 positive integers ai,bi,cia_i,b_i,c_i.

Output Format

There is 11 line in total. Output 11 non-negative integer, which is the required answer.

5 200
21 84 198
38 47 102
44 47 132 
63 150 166
76 79 132
4

Hint

Sample Explanation 1

All {x,y,z}\{x,y,z\} that satisfy the conditions are:

{88,88,120}\{88,88,120\}, {88,104,104}\{88,104,104\}, {120,120,120}\{120,120,120\}, and {120,136,104}\{120,136,104\}.

There are 44 in total.

Subtasks

For 10%10\% of the data, it is guaranteed to be exactly the same as the sample.

For 60%60\% of the data, it is guaranteed that M200M\leq 200.

For all data, it is guaranteed that ai,bi,ciM2000a_i,b_i,c_i\leq M\leq 2000 and n5n\leq 5.

Source

MtOI2019 Extra Round T2.

Problem setter: disangan233.

Problem tester: Studying Father.

Translated by ChatGPT 5