# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
1230528 | | just | Toy (CEOI24_toy) | C++20 | | 1597 ms | 87052 KiB |
#include "bits/stdc++.h"
using namespace std;
#define vec vector
#define int long long
#define all(x) (x).begin(), (x).end()
const int mod = 1e9 + 7;
const int inf = LLONG_MAX;
using pii = pair<int, int>;
using Point = pii;
#define X first
#define Y second
int n, m, w, h;
bool grid[100][100];
Point start;
bool valid(Point p) {
return p.X >= 0 && p.X < n && p.Y >= 0 && p.Y < m && !grid[p.X][p.Y];
}
Point meeting_point(Point H, Point V) {
return {H.X, V.Y};
}
bool valid(Point H, Point V) {
if (!valid(H) || !valid(V)) return false;
if (V.Y - H.Y > w - 1 || H.X - V.X > h - 1 || V.Y < H.Y || H.X < V.X) return false;
for (int i = 0; i < w; i++) {
if (!valid({H.X, H.Y + i})) return false;
}
for (int i = 0; i < h; i++) {
if (!valid({V.X + i, V.Y})) return false;
}
return true;
}
char print_buf[100][100];
void print(Point H, Point V) {
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) print_buf[i][j] = grid[i][j] ? '-' : '.';
print_buf[start.X][start.Y] = '*';
for (int i = 0; i < w; i++) print_buf[H.X][H.Y + i] = 'H';
for (int i = 0; i < h; i++) print_buf[V.X + i][V.Y] = 'V';
Point M = meeting_point(H, V);
print_buf[M.X][M.Y] = 'M';
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cout << print_buf[i][j];
cout << '\n';
}
cout << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> m >> n >> w >> h;
Point H, V;
{
int x, y;
cin >> x >> y;
H = {y, x};
cin >> x >> y;
V = {y, x};
}
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
char c; cin >> c;
grid[i][j] = c == 'X';
if (c == '*') start = {i, j};
}
// print(H, V);
assert(valid(H) && valid(V));
auto M = meeting_point(H, V);
if (M == start) {
cout << "YES\n";
return 0;
}
using State = pair<Point, Point>;
queue<State> q;
set<State> vis;
q.push({H, V});
vis.insert({H, V});
while (!q.empty()) {
auto [H, V] = q.front();
q.pop();
for (int s: {1, -1}) {
for (int i = 0; i < 4; i++) {
Point nH = {H.X + (i == 0) * s, H.Y + (i == 1) * s};
Point nV = {V.X + (i == 2) * s, V.Y + (i == 3) * s};
if (valid(nH, nV)) {
auto M = meeting_point(nH, nV);
if (M == start) {
cout << "YES\n";
return 0;
}
if (vis.count({nH, nV})) continue;
q.push({nH, nV});
vis.insert({nH, nV});
}
}
}
}
cout << "NO\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |