#abc250a. A - Adjacent Squares

A - Adjacent Squares

Score : 100100 points

问题描述

存在一个包含 HH 行(水平方向)和 WW 列(垂直方向)的网格。令 (i,j)(i,j) 表示从上到下的第 ii 行、从左到右的第 jj 列的方格。

找出与方格 (R,C)(R, C) 共享边的方格数量。

这里,两个方格 (a,b)(a,b)(c,d)(c,d) 被认为共享一条边当且仅当 ac+bd=1|a-c|+|b-d|=1(其中 x|x| 表示 xx 的绝对值)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a grid with HH horizontal rows and WW vertical columns. Let (i,j)(i,j) denote the square at the ii-th row from the top and the jj-th column from the left.
Find the number of squares that share a side with Square (R,C)(R, C).

Here, two squares (a,b)(a,b) and (c,d)(c,d) are said to share a side if and only if ac+bd=1|a-c|+|b-d|=1 (where x|x| denotes the absolute value of xx).

Constraints

  • All values in input are integers.
  • 1RH101 \le R \le H \le 10
  • 1CW101 \le C \le W \le 10

Input

Input is given from Standard Input in the following format:

HH WW

RR CC

Output

Print the answer as an integer.

Sample Input 1

3 4
2 2

Sample Output 1

4

We will describe Sample Inputs/Outputs 1,21,2, and 33 at once below Sample Output 33.

Sample Input 2

3 4
1 3

Sample Output 2

3

Sample Input 3

3 4
3 4

Sample Output 3

2

When H=3H=3 and W=4W=4, the grid looks as follows.

  • For Sample Input 11, there are 44 squares adjacent to Square (2,2)(2,2).
  • For Sample Input 22, there are 33 squares adjacent to Square (1,3)(1,3).
  • For Sample Input 33, there are 22 squares adjacent to Square (3,4)(3,4).

Sample Input 4

1 10
1 5

Sample Output 4

2

Sample Input 5

8 1
8 1

Sample Output 5

1

Sample Input 6

1 1
1 1

Sample Output 6

0

update @ 2024/3/10 10:40:28