#CCBCHBA0000021. Tích các số khác 0 (Product of Nonzero Values)
Tích các số khác 0 (Product of Nonzero Values)
Product of Nonzero Values
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Multiply all nonzero values among n integers. If there is no nonzero value, output 0, including n=0.
Input
n in [0,20], followed by n integers in [-5,5].
Output
The 64-bit product, or 0 if no nonzero element exists.
Subtasks
- Subtask 1 (20%): , .
- Subtask 2 (30%): , .
- Subtask 3 (50%): , .
Examples
Example 1
Input
5
0 -2 0 3 1
Output
-6
Explanation
Ignore zeros and multiply (-2)31=-6.
Example 2
Input
3
0 0 0
Output
0
Explanation
No nonzero factor exists, so output 0.