ICPC Miền Trung 2024-2025 - Bài G: Corner-Shared Cells
Đề bài
G. Corner-Shared Cells
Standard I/O | Time Limit: 1s | Memory Limit: 512 MB
(Python on oj.vietnamson.com: 2s)
Consider a squared-cell grid with $M$ horizontal rows and $N$ vertical columns. We denote $(i, j)$ as the cell on the intersection of $i$-th row and $j$-th column. Given integers $p$ and $q$, Gia Han is wondering how many cells share at least one corner with the cell $(p, q)$. Two cells $(i, j)$ and $(k, l)$ are said to share a corner if $|i - k| \le 1$ and $|j - l| \le 1$. Let's program to help her calculate the answer!.
Input
The first line contains two integers $M, N$ $(1 \le M, N \le 200)$
The second line contains two integers $p, q$ $(1 \le p \le M,$ $1 \le q \le N)$.
Output
Print the number of cells in the grid which share at least one corner with the cell $(p, q)$.
Explanation of the first case
| (1,1) | (1,2) | (1,3) |
| (2,1) | (2,2) | (2,3) |
| (3,1) | (3,2) | (3,3) |
| (4,1) | (4,2) | (4,3) |
The cell (4,2) shares at least one corner with the cells (3,1), (3,2), (3,3), (4,1), and (4,3).
Note (VIETNAMSON)
- Problem of The ICPC 2024 - Vietnam Central Provincial Contest (University of Science and Technology - The University of Danang). The statement and samples are kept verbatim from the original PDF.
- In the original PDF all samples are printed in one table; here they are split into separate samples (content unchanged).
- The cell $(p, q)$ itself is not counted (sample 1: answer 5).
- Python on oj.vietnamson.com: time limit 2 s, memory limit 1 GB.
Input
4 3
4 2
Output
5Input
4 3
3 2
Output
8Ý tưởng và lời giải chi tiết
Phần phân tích ý tưởng, các cách giải từ cơ bản đến tối ưu kèm code C++/Python và chấm thử trên VIETNAMSON OJ dành cho học viên đã đăng ký gói.
- Không biết học gì trước, học gì sau, học lan man nên kiến thức bị hổng.
- Bí bài không ai gỡ, ngồi cả buổi vẫn không ra rồi bỏ cuộc.
- Code chạy được nhưng không đủ điểm, không biết sai ở đâu, chậm ở đâu.
- Không có đề thi thử và người chấm, nên không biết mình đang ở mức nào.
- Dễ nản giữa chừng khi không có ai theo sát.
- Lộ trình 111 buổi video sắp sẵn từ dòng code đầu tiên đến đề HSG thật của các tỉnh.
- Thầy trực tiếp gỡ bí, chữa bài cho từng em qua nhóm Zalo riêng.
- Hệ thống chấm bài tự động 24/7 và thi thử HSG hằng tuần để biết chính xác mình đang ở đâu.
- Đóng học phí một lần, thầy kèm lâu dài: từ thi chuyên Tin đến HSG quốc gia và cả khi lên đại học.
