Submission #1084104

# Submission time Handle Problem Language Result Execution time Memory
1084104 2024-09-05T08:19:05 Z hemaprakash Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1028 ms 44108 KB
#include <bits/stdc++.h>

using namespace std;

int dir_x[] = {1, -1, 0, 0};
int dir_y[] = {0, 0, 1, -1};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<char>> grid(n, vector<char> (m));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin >> grid[i][j];
        }
    }
    if(grid[0][0] == '.' || grid[n - 1][m - 1] == '.')
    {
        cout << 0;
        return 0;
    }
    queue<pair<int, int>> fox, rabbit;
    vector<vector<bool>> visited(n, vector<bool> (m));
    if(grid[0][0] == 'F')
    {
        fox.push({0, 0});
    }
    else
    {
        rabbit.push({0, 0});
    }
    visited[0][0] = true;
    int ans = 0;
    while(fox.size() || rabbit.size())
    {
        if(fox.size())
        {
            ans++;
        }
        while(fox.size())
        {
            auto src = fox.front();
            fox.pop();
            for(int i = 0; i < 4; i++)
            {
                int x = src.first + dir_x[i], y = src.second + dir_y[i];
                if(x >= 0 && x < n && y >= 0 && y < m && visited[x][y] == false && grid[x][y] != '.')
                {
                    visited[x][y] = true;
                    if(grid[x][y] == 'F')
                    {
                        fox.push({x, y});
                    }
                    else
                    {
                        rabbit.push({x, y});
                    }
                }
            }
        }
        if(rabbit.size())
        {
            ans++;
        }
        while(rabbit.size())
        {
            auto src = rabbit.front();
            rabbit.pop();
            for(int i = 0; i < 4; i++)
            {
                int x = src.first + dir_x[i], y = src.second + dir_y[i];
                if(x >= 0 && x < n && y >= 0 && y < m && visited[x][y] == false && grid[x][y] != '.')
                {
                    visited[x][y] = true;
                    if(grid[x][y] == 'F')
                    {
                        fox.push({x, y});
                    }
                    else
                    {
                        rabbit.push({x, y});
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 8 ms 860 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 436 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 4 ms 608 KB Output is correct
15 Correct 15 ms 932 KB Output is correct
16 Correct 15 ms 860 KB Output is correct
17 Correct 12 ms 860 KB Output is correct
18 Correct 9 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 79 ms 3768 KB Output is correct
3 Correct 627 ms 34124 KB Output is correct
4 Correct 161 ms 8276 KB Output is correct
5 Correct 349 ms 19400 KB Output is correct
6 Correct 1028 ms 43980 KB Output is correct
7 Correct 3 ms 856 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 452 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 77 ms 3760 KB Output is correct
14 Correct 42 ms 2396 KB Output is correct
15 Correct 38 ms 2384 KB Output is correct
16 Correct 33 ms 1628 KB Output is correct
17 Correct 188 ms 9060 KB Output is correct
18 Correct 147 ms 8788 KB Output is correct
19 Correct 146 ms 8360 KB Output is correct
20 Correct 122 ms 7672 KB Output is correct
21 Correct 337 ms 20004 KB Output is correct
22 Correct 338 ms 19272 KB Output is correct
23 Correct 377 ms 16724 KB Output is correct
24 Correct 341 ms 19536 KB Output is correct
25 Correct 634 ms 34140 KB Output is correct
26 Correct 581 ms 26228 KB Output is correct
27 Correct 814 ms 35664 KB Output is correct
28 Correct 972 ms 44108 KB Output is correct
29 Correct 958 ms 42440 KB Output is correct
30 Correct 870 ms 41184 KB Output is correct
31 Correct 768 ms 22352 KB Output is correct
32 Correct 746 ms 34640 KB Output is correct