Submission #1196702

#TimeUsernameProblemLanguageResultExecution timeMemory
1196702mmaitiToy (CEOI24_toy)C++20
73 / 100
1594 ms15028 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define vi vector<int> #define si set<int> #define usi unordered_set<int> #define sll set<ll> #define usll unordered_set<ll> #define vb vector<bool> #define vll vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define vvi vector<vector<int>> #define vvll vector<vector<ll>> // xh, yh, xv, yv bool visited[1500][1500]; void solve() { int W, H, K, L; cin >> W >> H >> K >> L; int xh, yh, xv, yv, gx, gy; cin >> yh >> xh >> yv >> xv; vector<string> grid(H); for (int i = 0; i < H; i++) cin >> grid[i]; vector<vi> psum(H + 1, vi(W + 1)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (grid[i][j] == '*') { gx = i; gy = j; } psum[i + 1][j + 1] = (grid[i][j] == 'X') + psum[i][j + 1] + psum[i + 1][j] - psum[i][j]; } } vll dx{-1, 0, 1, 0}; vll dy{0, 1, 0, -1}; queue<pair<int, int>> q; q.push(make_pair(xh, yv)); // x1, y1 are top left, x2, y2 are bottom right // all values are 0 indexed auto queryRegion = [&](ll x1, ll y1, ll x2, ll y2) { return psum[x2 + 1][y2 + 1] - psum[x1][y2 + 1] - psum[x2 + 1][y1] + psum[x1][y1]; }; auto checkCoord = [&](ll x, ll y) { return (x >= 0 && x < H && y >= 0 && y < W); }; // x1, y1 are horizontal piece; x2, y2 are vertical piece auto checkHoriz = [&](ll x1, ll y1) { bool works = true; works &= checkCoord(x1, y1); works &= checkCoord(x1, y1 + K - 1); if (!works) return false; // check no obstacle intersection works &= (queryRegion(x1, y1, x1, y1 + K - 1) == 0); return works; }; auto checkVert = [&](ll x2, ll y2) { bool works = true; works &= checkCoord(x2, y2); works &= checkCoord(x2 + L - 1, y2); if (!works) return false; // check no obstacle intersection works &= (queryRegion(x2, y2, x2 + L - 1, y2) == 0); return works; }; while (!q.empty()) { int cx, cy; tie(cx, cy) = q.front(); q.pop(); if (cx == gx && cy == gy) { cout << "YES\n"; return; } for (int i = 0; i < 4; i++) { int nxh = cx + dx[i]; int nyh = cy + dy[i]; if (!checkCoord(nxh, nyh) || grid[nxh][nyh] == 'X' || visited[nxh][nyh]) continue; if (abs(dy[i]) == 1) { for (int j = cx - L + 1; j <= cx; j++) { if (checkVert(j, cy) && checkVert(j, nyh)) { visited[nxh][nyh] = true; q.push({nxh, nyh}); } } } else { for (int j = cy - K + 1; j <= cy; j++) { if (checkHoriz(cx, j) && checkHoriz(nxh, j)) { visited[nxh][nyh] = true; q.push({nxh, nyh}); } } } } } cout << "NO\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); solve(); }
#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...