#CCBOTPBA0000029. Đếm điểm trên viền bảng (Border Cells of a Grid)
Đếm điểm trên viền bảng (Border Cells of a Grid)
Border Cells of a Grid
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Count distinct border cells of an n-by-m grid; a cell is on the border if it lies in the first/last row or first/last column. All cells are border cells if n=1 or m=1.
Input
Two positive integers n m.
Output
Number of border cells as a 64-bit integer.
Subtasks
-
Subtask 1 (20%):
1 ≤ n,m ≤ 20. -
Subtask 2 (30%):
1 ≤ n,m ≤ 1000. -
Subtask 3 (50%):
1 ≤ n,m ≤ 10^6.
Examples
Example 1
Input:
3 4
Output:
10
Explanation: Twelve total cells minus two interior cells give ten border cells.
Example 2
Input:
1 5
Output:
5
Explanation: All five cells of a one-row grid are border cells.