PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000231. Tổng hình vuông xoay 45 độ (Rotated Square Sum)
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ổng hình vuông xoay 45 độ (Rotated Square Sum)
Rotated Square Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a static integer matrix indexed from 1, each query asks for the sum of cells satisfying . Ignore positions outside the matrix.
Input
The first line contains , followed by rows of integers. Each of the next lines contains .
Output
Print lines, one diamond sum per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Example 1
Input
3 3
1 2 3
4 5 6
7 8 9
2 2 1
1 1 1
3 3 6
Output
25
7
45
Explanation
The first diamond includes 2,4,5,6,8. The corner includes 1,2,4. The last query covers the grid.
Example 2
Input
1 1
-9
1 1 2
Output
-9
Explanation
Only the cell −9 lies in the grid.