답안 #1084113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084113 2024-09-05T08:25:33 Z hemaprakash Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1036 ms 43984 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];
        }
    }
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 856 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 9 ms 860 KB Output is correct
5 Correct 4 ms 448 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 456 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 6 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 14 ms 928 KB Output is correct
16 Correct 15 ms 1040 KB Output is correct
17 Correct 12 ms 920 KB Output is correct
18 Correct 9 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 77 ms 3780 KB Output is correct
3 Correct 575 ms 33876 KB Output is correct
4 Correct 144 ms 8272 KB Output is correct
5 Correct 343 ms 19280 KB Output is correct
6 Correct 958 ms 43984 KB Output is correct
7 Correct 3 ms 856 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 73 ms 3772 KB Output is correct
14 Correct 42 ms 2388 KB Output is correct
15 Correct 36 ms 2436 KB Output is correct
16 Correct 31 ms 1628 KB Output is correct
17 Correct 199 ms 9040 KB Output is correct
18 Correct 146 ms 8752 KB Output is correct
19 Correct 132 ms 8272 KB Output is correct
20 Correct 120 ms 7508 KB Output is correct
21 Correct 353 ms 20024 KB Output is correct
22 Correct 334 ms 19144 KB Output is correct
23 Correct 378 ms 16720 KB Output is correct
24 Correct 332 ms 19388 KB Output is correct
25 Correct 632 ms 33872 KB Output is correct
26 Correct 587 ms 26096 KB Output is correct
27 Correct 780 ms 35532 KB Output is correct
28 Correct 941 ms 43964 KB Output is correct
29 Correct 1036 ms 42568 KB Output is correct
30 Correct 835 ms 40996 KB Output is correct
31 Correct 747 ms 22212 KB Output is correct
32 Correct 729 ms 34640 KB Output is correct