I wrote hash during the competition and had timed out. Later I realized that I had not removed the same value, so I gave up the optimization. I will think about it later.
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
# Include <memory. h>
# Define ll _ int64
# Define mm 100007
Using namespace std;
Ll sum [5] [210];
Struct Node
{
Ll real;
} Node [2, 40010];
Int hash [mm], next [40010];
Int cnt;
Void add (ll key)
{
Ll tem = key % mm;
If (tem <0) tem + = mm;
Int I = hash [tem];
While (I! =-1)
{
If (key = node [I]. real)
Return;
I = next [I];
}
Node [cnt]. real = key;
Next [cnt] = hash [tem];
Hash [tem] = cnt ++;
Return;
}
Int find (ll tem)
{
Ll key = (-tem) % mm;
If (key <0) key + = mm;
Int I = hash [key];
While (I! =-1)
{
If (node [I]. real + tem = 0)
Return 1;
I = next [I];
}
Return 0;
}
Int main ()
{
Int t, n;
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n );
For (int I = 0; I <5; I ++)
For (int j = 0; j <n; j ++)
Scanf ("% I64d", & sum [I] [j]);
Memset (hash,-1, sizeof (hash ));
Cnt = 0;
For (int I = 0; I <n; I ++)
For (int j = 0; j <n; j ++)
{
Add (sum [0] [I] + sum [1] [j]);
}
Bool flag = false;
For (int I = 0; I <n &&! Flag; I ++)
For (int j = 0; j <n &&! Flag; j ++)
For (int k = 0; k <n &&! Flag; k ++)
{
If (find (sum [2] [I] + sum [3] [j] + sum [4] [k])
{
Flag = true;
Break;
}
}
If (flag)
Cout <"Yes" <endl;
Else
Cout <"No" <endl;
}
Return 0;
}
Author: qiqijianglu