Submission #1075697

# Submission time Handle Problem Language Result Execution time Memory
1075697 2024-08-26T08:40:51 Z raphaelp Toy (CEOI24_toy) C++14
9 / 100
9 ms 2396 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int W, H, K, L;
    cin >> W >> H >> K >> L;
    vector<vector<int>> dp(H, vector<int>(W, 0));
    vector<vector<pair<int, int>>> cumH(H, vector<pair<int, int>>(W, {1000000, 1000000})), cumW(H, vector<pair<int, int>>(W, {1000000, 1000000}));
    int x1, x2, y1, y2;
    queue<pair<int, int>> Q;
    cin >> y1 >> x1 >> y2 >> x2;
    Q.push({x1, y2});
    pair<int, int> targ;
    for (int i = 0; i < H; i++)
    {
        string S;
        cin >> S;
        for (int j = 0; j < W; j++)
        {
            if (S[j] == '*')
                targ = {i, j};
            if (S[j] == 'X')
            {
                cumH[i][j].first = 0;
                cumH[i][j].second = 0;
                cumW[i][j].first = 0;
                cumW[i][j].second = 0;
            }
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (i == 0)
            {
                cumH[i][j].first = min(cumH[i][j].first, 1);
            }
            else
            {
                cumH[i][j].first = min(cumH[i][j].first, cumH[i - 1][j].first + 1);
            }
            if (j == 0)
            {
                cumW[i][j].first = min(cumW[i][j].first, 1);
            }
            else
            {
                cumW[i][j].first = min(cumW[i][j].first, cumW[i][j - 1].first + 1);
            }
        }
    }
    for (int i = H - 1; i >= 0; i--)
    {
        for (int j = W - 1; j >= 0; j--)
        {
            if (i == H - 1)
            {
                cumH[i][j].second = min(cumH[i][j].second, 1);
            }
            else
            {
                cumH[i][j].second = min(cumH[i][j].second, cumH[i + 1][j].second + 1);
            }
            if (j == W - 1)
            {
                cumW[i][j].second = min(cumW[i][j].second, 1);
            }
            else
            {
                cumW[i][j].second = min(cumW[i][j].second, cumW[i][j + 1].second + 1);
            }
        }
    }
    while (!Q.empty())
    {
        int x = Q.front().first;
        int y = Q.front().second;
        Q.pop();
        if (dp[x][y])
            continue;
        dp[x][y] = 1;
        if (x > 0)
        {
            if (min(cumW[x][y].first, cumW[x - 1][y].first) + min(cumW[x][y].second, cumW[x - 1][y].second) > L)
            {
                Q.push({x - 1, y});
            }
        }
        if (x < H - 1)
        {
            if (min(cumW[x][y].first, cumW[x + 1][y].first) + min(cumW[x][y].second, cumW[x + 1][y].second) > L)
            {
                Q.push({x + 1, y});
            }
        }
        if (y > 0)
        {
            if (min(cumH[x][y].first, cumH[x][y - 1].first) + min(cumH[x][y].second, cumH[x][y - 1].second) > K)
            {
                Q.push({x, y - 1});
            }
        }
        if (y < W - 1)
        {
            if (min(cumH[x][y].first, cumH[x][y + 1].first) + min(cumH[x][y].second, cumH[x][y + 1].second) > K)
            {
                Q.push({x, y + 1});
            }
        }
    }
    if (dp[targ.first][targ.second])
        cout << "YES";
    else
        cout << "NO";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 9 ms 2392 KB Output is correct
5 Correct 7 ms 2140 KB Output is correct
6 Correct 1 ms 664 KB Output is correct
7 Correct 6 ms 2336 KB Output is correct
8 Correct 7 ms 2236 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 3 ms 2140 KB Output is correct
11 Correct 4 ms 2396 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 4 ms 2140 KB Output is correct
14 Correct 4 ms 2140 KB Output is correct
15 Correct 6 ms 2140 KB Output is correct
16 Correct 8 ms 2140 KB Output is correct
17 Correct 7 ms 2140 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 6 ms 2140 KB Output is correct
20 Correct 9 ms 2176 KB Output is correct
21 Correct 6 ms 2140 KB Output is correct
22 Correct 7 ms 2324 KB Output is correct
23 Correct 7 ms 2140 KB Output is correct
24 Correct 5 ms 2324 KB Output is correct
25 Correct 6 ms 2240 KB Output is correct
26 Correct 6 ms 2140 KB Output is correct
27 Correct 9 ms 2140 KB Output is correct
28 Correct 7 ms 2104 KB Output is correct
29 Correct 7 ms 2140 KB Output is correct
30 Correct 6 ms 2140 KB Output is correct
31 Correct 5 ms 2140 KB Output is correct
32 Correct 7 ms 2140 KB Output is correct
33 Correct 9 ms 2140 KB Output is correct
34 Correct 6 ms 2140 KB Output is correct
35 Correct 6 ms 1984 KB Output is correct
36 Correct 3 ms 2136 KB Output is correct
37 Correct 3 ms 2140 KB Output is correct
38 Correct 4 ms 1884 KB Output is correct
39 Correct 4 ms 2140 KB Output is correct
40 Correct 4 ms 2136 KB Output is correct
41 Correct 4 ms 2132 KB Output is correct
42 Correct 6 ms 2140 KB Output is correct
43 Correct 8 ms 2320 KB Output is correct
44 Correct 8 ms 2324 KB Output is correct
45 Correct 6 ms 2136 KB Output is correct
46 Correct 3 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -