PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000061. Đếm bộ bốn có tổng bằng không (4 values whose sum is 0)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm bộ bốn có tổng bằng không (4 values whose sum is 0)
4 values whose sum is 0
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Four integer arrays are given, each containing exactly elements. Input row gives the four values .
Choose one index from each array independently, forming with . It qualifies if . Indices in different arrays may have the same numerical position; equal values do not merge distinct index quadruples.
Count all qualifying quadruples.
Input
- The first line contains integer : the size of each array.
- Each of the next lines contains four integers , in that order.
Output
Print one integer: the number of index quadruples with sum zero.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45
Output
5
Explanation
The five valid index quadruples are , , , , and . Their sums are , , , , and . Each quadruple picks one index from each of the four arrays, and there are no other valid choices. Thus the answer is 5.