From 213986c458e65f6e34c49f544c8b2ba031d2a8fc Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 18 Nov 2022 14:24:39 +0800 Subject: [PATCH] =?UTF-8?q?P4030=20[Code+#2]=E5=8F=AF=E5=81=9A=E9=A2=981?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/94434358 --- Luogu/P4030/P4030.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Luogu/P4030/P4030.cpp diff --git a/Luogu/P4030/P4030.cpp b/Luogu/P4030/P4030.cpp new file mode 100644 index 00000000..034e3587 --- /dev/null +++ b/Luogu/P4030/P4030.cpp @@ -0,0 +1,49 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 505; + +int n, m, t, a[N][N], s[N][N]; +bool g[N][N]; + +int sum(int x1, int y1, int x2, int y2) { + return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m >> t; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + } + } + + for (int i = 1; i < n; i++) { + for (int j = 1; j < m; j++) { + g[i][j] = a[i][j] + a[i + 1][j + 1] == a[i + 1][j] + a[i][j + 1]; + } + } + + for (int i = 1; i < n; i++) { + for (int j = 1; j < m; j++) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + g[i][j]; + } + } + + while (t--) { + int x, y, k; + + cin >> x >> y >> k; + + cout << (k == 1 || sum(x, y, x + k - 2, y + k - 2) == (k - 1) * (k - 1) ? 'Y' : 'N') << endl; + } + + return 0; +}