답안 #965552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965552 2024-04-18T21:22:36 Z OIaspirant2307 Tracks in the Snow (BOI13_tracks) C++17
2.1875 / 100
1405 ms 413744 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define pi pair<int, int>
#define f first
#define s second
const int N = 4005;
vector<vector<char>> grid(N, vector<char>(N));
vector<vector<bool>> vis(N, vector<bool>(N, 0));
vector<pi> rabbits;
vector<pi> foxes;
vector<pi> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, m;

bool ok(int i, int j)
{
    return (i >= 0 && i < n && j >= 0 && j < m && grid[i][j] != '.' && !vis[i][j]);
}

void bfs(pi pos)
{
    queue<pi> q;
    q.push({pos.f, pos.s});
    vis[pos.f][pos.s] = true;
    while (!q.empty())
    {
        auto p = q.front();
        q.pop();
        for (auto move : moves)
        {
            if (ok(p.f + move.f, p.s + move.s))
            {
                vis[p.f + move.f][p.s + move.s] = true;
                q.push({p.f + move.f, p.s + move.s});
            }
        }
    }
}

signed main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> grid[i][j];
            if (grid[i][j] == 'R')
            {
                rabbits.push_back({i, j});
            }
            else if (grid[i][j] == 'F')
            {
                foxes.push_back({i, j});
            }
        }
    }
    int ans = 0;
    for (auto p : rabbits)
    {
        if (!vis[p.f][p.s])
        {
            bfs({p.f, p.s});
            ans++;
        }
    }
    vis.resize(n + 1, vector<bool>(m + 1, 0));
    for (auto p : foxes)
    {
        if (!vis[p.f][p.s])
        {
            bfs({p.f, p.s});
            ans++;
        }
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 22292 KB Output isn't correct
2 Incorrect 11 ms 18268 KB Output isn't correct
3 Incorrect 10 ms 18580 KB Output isn't correct
4 Incorrect 21 ms 21660 KB Output isn't correct
5 Incorrect 20 ms 19224 KB Output isn't correct
6 Incorrect 10 ms 18268 KB Output isn't correct
7 Incorrect 10 ms 18424 KB Output isn't correct
8 Incorrect 11 ms 18520 KB Output isn't correct
9 Incorrect 11 ms 18268 KB Output isn't correct
10 Incorrect 14 ms 18904 KB Output isn't correct
11 Incorrect 13 ms 19416 KB Output isn't correct
12 Incorrect 17 ms 20004 KB Output isn't correct
13 Incorrect 14 ms 18972 KB Output isn't correct
14 Incorrect 15 ms 18968 KB Output isn't correct
15 Incorrect 29 ms 21960 KB Output isn't correct
16 Incorrect 28 ms 22216 KB Output isn't correct
17 Incorrect 25 ms 20340 KB Output isn't correct
18 Incorrect 22 ms 21784 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 18776 KB Output isn't correct
2 Incorrect 100 ms 35248 KB Output isn't correct
3 Incorrect 714 ms 96136 KB Output isn't correct
4 Incorrect 174 ms 36804 KB Output isn't correct
5 Incorrect 471 ms 127380 KB Output isn't correct
6 Incorrect 1405 ms 413744 KB Output isn't correct
7 Incorrect 13 ms 18776 KB Output isn't correct
8 Incorrect 13 ms 18780 KB Output isn't correct
9 Incorrect 16 ms 19036 KB Output isn't correct
10 Incorrect 12 ms 18464 KB Output isn't correct
11 Incorrect 13 ms 18524 KB Output isn't correct
12 Incorrect 12 ms 18556 KB Output isn't correct
13 Incorrect 90 ms 34204 KB Output isn't correct
14 Incorrect 67 ms 27208 KB Output isn't correct
15 Incorrect 58 ms 27136 KB Output isn't correct
16 Incorrect 46 ms 26040 KB Output isn't correct
17 Incorrect 214 ms 50316 KB Output isn't correct
18 Incorrect 220 ms 49596 KB Output isn't correct
19 Incorrect 172 ms 35484 KB Output isn't correct
20 Incorrect 158 ms 36568 KB Output isn't correct
21 Incorrect 408 ms 77080 KB Output isn't correct
22 Incorrect 457 ms 127348 KB Output isn't correct
23 Incorrect 415 ms 77204 KB Output isn't correct
24 Incorrect 435 ms 77372 KB Output isn't correct
25 Incorrect 811 ms 135052 KB Output isn't correct
26 Correct 918 ms 289428 KB Output is correct
27 Incorrect 1263 ms 361412 KB Output isn't correct
28 Incorrect 1296 ms 413340 KB Output isn't correct
29 Incorrect 1372 ms 284684 KB Output isn't correct
30 Incorrect 1206 ms 364612 KB Output isn't correct
31 Incorrect 843 ms 225220 KB Output isn't correct
32 Incorrect 1115 ms 299172 KB Output isn't correct