Time limit:15000 Ms
Memory limit:228000kb
64bit Io format:% I64d & % i64usubmit status
Description
The sum problem can be formulated as follows: given four Lists A, B, C, D of integer values, compute how many quadruplet (A, B, C, D) ε a x B x C x D are such that A + B + C + D = 0. in the following, we assume that all lists have the same size N.
Input
The first line of the input file contains the size of the lists N (this value can be as large as 4000 ). we then have n lines containing four integer values (with absolute value as large as 2 28) that belong respectively to A, B, C and D.
Output
For each input file, your program has to write the number quadruplets whose sum is zero.
Sample Input
6-45 22 42 -16-41 -27 56 30-36 53 -37 77
1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 #define MAXN 4400 5 using namespace std; 6 int A[MAXN],B[MAXN],C[MAXN],D[MAXN]; 7 int S[MAXN*MAXN]; 8 int lower_bound1(int low,int high,int num,int a[]) 9 {10 int mid;11 while(low
-36 30 -75 -4626 -38 -10 62-32 -54 -6 45
Sample output
5
Hint
Sample explanation: indeed, the sum of the five following quadruplets is zero: (-45,-27, 42, 30), (26, 30,-10,-46 ), (-32, 22, 56,-46), (-32, 30,-75, 77), (-32,-54, 56, 30 ).