답안 #1053453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053453 2024-08-11T12:03:47 Z elazarkoren Toy (CEOI24_toy) C++17
9 / 100
6 ms 13148 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;

const int MAX_N = 1505;
int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};

int dp_u[MAX_N][MAX_N], dp_d[MAX_N][MAX_N], dp_l[MAX_N][MAX_N], dp_r[MAX_N][MAX_N];
int n, m, k, l;

bool Check(int x, int y, int nx, int ny) {
    if (x == nx) {
        int u = max(dp_u[x][y], dp_u[nx][ny]);
        int d = min(dp_d[x][y], dp_d[nx][ny]);
        return d - u + 1 >= k;
    }
    int le = max(dp_l[x][y], dp_l[nx][ny]);
    int r = min(dp_r[x][y], dp_r[nx][ny]);
    return r - le + 1 >= l;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> m >> n >> k >> l;
    int xh, yh, xv, yv, xt, yt;
    cin >> xh >> yh >> xv >> yv;
    vvb visited(n, vb(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            char c;
            cin >> c;
            if (c == '*') {
                xt = i, yt = j;
            } else if (c == 'X') visited[i][j] = 1;
        }
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp_u[i][j] = visited[i - 1][j] ? i : dp_u[i - 1][j];
        }
    }
    for (int j = 0; j < m; j++) dp_d[n - 1][j] = n - 1;
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j < m; j++) {
            dp_d[i][j] = visited[i + 1][j] ? i : dp_d[i + 1][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < m; j++) {
            dp_l[i][j] = visited[i][j - 1] ? j : dp_l[i][j - 1];
        }
    }
    for (int i = 0; i < n; i++) dp_r[i][m - 1] = m - 1;
    for (int i = 0; i < n; i++) {
        for (int j = m - 2; j >= 0; j--) {
            dp_r[i][j] = visited[i][j + 1] ? j : dp_r[i][j + 1];
        }
    }

    queue<pii> q;
    q.push({yh, xv});
    visited[yh][xv] = 1;
    while (!q.empty()) {
        auto [x, y] = q.front();
        q.pop();
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (0 > nx || nx >= n || 0 > ny || ny >= m || visited[nx][ny]) continue;
            if (Check(x, y, nx, ny)) {
                q.push({nx, ny});
                visited[nx][ny] = 1;
            }
        }
    }
    cout << (visited[xt][yt] ? "YES\n" : "NO\n");
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:88:24: warning: 'xt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |     cout << (visited[xt][yt] ? "YES\n" : "NO\n");
      |                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 0 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 0 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 3 ms 10536 KB Output is correct
5 Correct 4 ms 10588 KB Output is correct
6 Correct 1 ms 7260 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 3 ms 10588 KB Output is correct
9 Correct 1 ms 7416 KB Output is correct
10 Correct 3 ms 10588 KB Output is correct
11 Correct 3 ms 10588 KB Output is correct
12 Correct 2 ms 10076 KB Output is correct
13 Correct 4 ms 13148 KB Output is correct
14 Correct 4 ms 13148 KB Output is correct
15 Correct 3 ms 10552 KB Output is correct
16 Correct 3 ms 10556 KB Output is correct
17 Correct 5 ms 10584 KB Output is correct
18 Correct 4 ms 10588 KB Output is correct
19 Correct 4 ms 10564 KB Output is correct
20 Correct 3 ms 10588 KB Output is correct
21 Correct 4 ms 10564 KB Output is correct
22 Correct 3 ms 10588 KB Output is correct
23 Correct 3 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
26 Correct 3 ms 10720 KB Output is correct
27 Correct 3 ms 10588 KB Output is correct
28 Correct 4 ms 10588 KB Output is correct
29 Correct 3 ms 10584 KB Output is correct
30 Correct 4 ms 10664 KB Output is correct
31 Correct 3 ms 10588 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 3 ms 10588 KB Output is correct
34 Correct 6 ms 10520 KB Output is correct
35 Correct 3 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 3 ms 10588 KB Output is correct
38 Correct 3 ms 10588 KB Output is correct
39 Correct 2 ms 10588 KB Output is correct
40 Correct 2 ms 10588 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 4 ms 10840 KB Output is correct
43 Correct 4 ms 10584 KB Output is correct
44 Correct 5 ms 10584 KB Output is correct
45 Correct 4 ms 10588 KB Output is correct
46 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 0 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 0 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -