제출 #1213903

#제출 시각아이디문제언어결과실행 시간메모리
1213903MateiKing80Toy (CEOI24_toy)C++20
100 / 100
224 ms181084 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1505; int n, m, k, l, sx, sy, useless, dp[N][N][4]; char mat[N][N]; bool vis[N][N], yes; int dx[4] = {0, -1, 0, 1}; int dy[4] = {-1, 0, 1, 0}; bool valid(int x, int y) { return (0 <= x && x < n && 0 <= y && y < m && mat[x][y] != 'X'); } int intersection(int l1, int r1, int l2, int r2) { return max(0, min(r1, r2) - max(l1, l2) + 1); } void dfs(int x, int y) { vis[x][y] = 1; if (mat[x][y] == '*') yes = 1; for (int i = 0; i < 4; i ++) { int nx = x + dx[i]; int ny = y + dy[i]; if (!valid(nx, ny) || vis[nx][ny]) continue; if (intersection(y - dp[x][y][0] + 1, y + dp[x][y][2] - 1, ny - dp[nx][ny][0] + 1, ny + dp[nx][ny][2] - 1) < k) continue; if (intersection(x - dp[x][y][1] + 1, x + dp[x][y][3] - 1, nx - dp[nx][ny][1] + 1, nx + dp[nx][ny][3] - 1) < l) continue; dfs(nx, ny); } } int main() { cin >> m >> n >> k >> l; cin >> useless >> sx >> sy >> useless; for (int i = 0; i < n; i ++) for (int j = 0; j < m; j ++) cin >> mat[i][j]; for (int i = 0; i < n; i ++) { for (int j = 0; j < m; j ++) { if (!valid(i, j)) continue; if (!valid(i, j - 1)) dp[i][j][0] = 1; else dp[i][j][0] = dp[i][j - 1][0] + 1; if (!valid(i - 1, j)) dp[i][j][1] = 1; else dp[i][j][1] = dp[i - 1][j][1] + 1; } } for (int j = m - 1; j >= 0; j --) { for (int i = n - 1; i >= 0; i --) { if (!valid(i, j)) continue; if (!valid(i, j + 1)) dp[i][j][2] = 1; else dp[i][j][2] = dp[i][j + 1][2] + 1; if (!valid(i + 1, j)) dp[i][j][3] = 1; else dp[i][j][3] = dp[i + 1][j][3] + 1; } } dfs(sx, sy); cout << (yes ? "YES" : "NO") << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...