PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000287. Tích các phần tử ngoại trừ chính nó (Product of Array Except Self)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tích các phần tử ngoại trừ chính nó (Product of Array Except Self)
Product of Array Except Self
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
For every position in , compute . Output the results in original order. The intended algorithm is linear and uses no division.
Input
First line: . Second line: exactly integers .
Output
Print integers on one line.
Subtasks
- Subtask 1 (20 points): ; ; every prefix product, suffix product and fits in .
- Subtask 2 (30 points): ; ; every prefix product, suffix product and fits in ; at least two zeros.
- Subtask 3 (50 points): ; ; every prefix product, suffix product and fits in .
Example 1
Input
4
1 2 3 4
Output
24 12 8 6
Explanation
Omitting 1, 2, 3 and 4 gives 24, 12, 8 and 6 respectively.
Example 2
Input
5
-1 1 0 -3 3
Output
0 0 9 0 0
Explanation
Only omitting the zero at position 3 produces a nonzero product, equal to 9.