답안 #1039744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039744 2024-07-31T08:18:56 Z 중국공산당(#11033) Toy (CEOI24_toy) C++17
0 / 100
5 ms 11408 KB
#include <cstdio>
#include <cstdlib>

const int dt[4][2] = { 1, 0, -1, 0, 0, 1, 0, -1 };

int w, h, k, l;
int x, y, gx, gy;
char a[1506][1506];
int sum[1506][1506], b[1506][1506], c[1506][1506], d[1506][1506];


void f(int y, int x) {
    b[y][x] = 0;
    if (y == gy && x == gx) puts("YES"), exit(0);
    for (int t = 0; t < 4; t++) {
        int ny = y + dt[t][1], nx = x + dt[t][0];
        if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
        if (!b[ny][nx]) continue;
        if (y == ny && (!c[y][x] || !c[ny][nx])) continue;
        if (x == nx && (!d[y][x] || !d[ny][nx])) continue;
        f(ny, nx);
    }
}

int main() {
    scanf("%d%d%d%d", &w, &h, &k, &l);
    scanf("%*d%d%d%*d", &y, &x);
    for (int i = 0; i < h; i++) scanf("%s", a[i]);
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (a[i][j] == '*') gy = i, gx = j;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) sum[i][j] = (a[i][j] == 'X') + (i ? sum[i - 1][j] : 0) + (j ? sum[i][j - 1] : 0) - (i && j ? sum[i - 1][j - 1] : 0);
    for (int i = 0; i < h - l + 1; i++) for (int j = 0; j < w - k + 1; j++) {
        int curr = sum[i + l - 1][j + k - 1] - (i ? sum[i - 1][j + k - 1] : 0) - (j ? sum[i + l - 1][j - 1] : 0) + (i && j ? sum[i - 1][j - 1] : 0);
        if (!curr) b[i][j]++, b[i + l][j]--, b[i][j + k]--, b[i + l][j + k]++;
    }
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) b[i][j] += (i ? b[i - 1][j] : 0) + (j ? b[i][j - 1] : 0) - (i && j ? b[i - 1][j - 1] : 0);
    for (int i = 0; i < h - l + 1; i++) for (int j = 0; j < w; j++) {
        int curr = sum[i + l - 1][j] - (i ? sum[i - 1][j] : 0) - (j ? sum[i + l - 1][j - 1] : 0) + (i && j ? sum[i - 1][j - 1] : 0);
        if (!curr) c[i][j]++, c[i + l][j]--;
    }
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) c[i][j] += (i ? c[i - 1][j] : 0);
    for (int i = 0; i < h; i++) for (int j = 0; j < w - k + 1; j++) {
        int curr = sum[i][j + k - 1] - (i ? sum[i - 1][j + k - 1] : 0) - (j ? sum[i][j - 1] : 0) + (i && j ? sum[i - 1][j - 1] : 0);
        if (!curr) d[i][j]++, d[i][j + k]--;
    }
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) d[i][j] += (j ? d[i][j - 1] : 0);
    f(y, x);
    puts("NO");
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d%d%d%d", &w, &h, &k, &l);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%*d%d%d%*d", &y, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     for (int i = 0; i < h; i++) scanf("%s", a[i]);
      |                                 ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Incorrect 1 ms 3164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Incorrect 1 ms 3164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 5 ms 10844 KB Output is correct
6 Correct 1 ms 3932 KB Output is correct
7 Correct 5 ms 11408 KB Output is correct
8 Incorrect 4 ms 9564 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Incorrect 1 ms 3164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Incorrect 1 ms 3164 KB Output isn't correct
7 Halted 0 ms 0 KB -