Submission #926709

# Submission time Handle Problem Language Result Execution time Memory
926709 2024-02-13T14:30:17 Z htphong0909 Tracks in the Snow (BOI13_tracks) C++17
97.8125 / 100
974 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;
 
void File() {
#define file "ZOO"
    freopen(file".inp", "r", stdin);
    freopen(file".out", "w", stdout);
}
 
int n, m;
bool visited[4001][4001];
char arr[4001][4001];
vector<pair<int, int>> dif, nDif;
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
 
bool canGo(int x, int y)
{
    return (x <= n && y <= m && min(x, y) > 0 && arr[x][y] != '.' && !visited[x][y]);
}
 
void dfs(int x, int y)
{
    visited[x][y] = true;
    for (int i = 0; i < 4; i++)
    {
        int vx = x + dx[i];
        int vy = y + dy[i];
        if (canGo(vx, vy))
        {
            if (arr[vx][vy] == arr[x][y]) dfs(vx, vy);
            else nDif.emplace_back(vx, vy);
        }
    }
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //File();
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> arr[i][j];
        }
    }
    nDif.emplace_back(1, 1);
    int ans = 0;
    while (!nDif.empty())
    {
        ans++;
        dif = nDif;
        nDif.clear();
        for (pair<int, int> cur : dif) dfs(cur.first, cur.second);
        dif.clear();
    }
    cout << ans;
    return 0;
}

Compilation message

tracks.cpp: In function 'void File()':
tracks.cpp:6:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     freopen(file".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen(file".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 6236 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 8 ms 7904 KB Output is correct
5 Correct 2 ms 5028 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 3 ms 4700 KB Output is correct
11 Correct 3 ms 5724 KB Output is correct
12 Correct 6 ms 5212 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 12 ms 6096 KB Output is correct
16 Correct 15 ms 6236 KB Output is correct
17 Correct 9 ms 5724 KB Output is correct
18 Correct 7 ms 8156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 31324 KB Output is correct
2 Correct 44 ms 13148 KB Output is correct
3 Correct 281 ms 40224 KB Output is correct
4 Correct 62 ms 17756 KB Output is correct
5 Correct 152 ms 29060 KB Output is correct
6 Correct 669 ms 194992 KB Output is correct
7 Correct 8 ms 32092 KB Output is correct
8 Correct 9 ms 31324 KB Output is correct
9 Correct 3 ms 3164 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 8 ms 31836 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 44 ms 13144 KB Output is correct
14 Correct 26 ms 9564 KB Output is correct
15 Correct 21 ms 10204 KB Output is correct
16 Correct 25 ms 5696 KB Output is correct
17 Correct 110 ms 18312 KB Output is correct
18 Correct 64 ms 18216 KB Output is correct
19 Correct 67 ms 17780 KB Output is correct
20 Correct 61 ms 17240 KB Output is correct
21 Correct 178 ms 29804 KB Output is correct
22 Correct 153 ms 29260 KB Output is correct
23 Correct 210 ms 23808 KB Output is correct
24 Correct 140 ms 29960 KB Output is correct
25 Correct 298 ms 40060 KB Output is correct
26 Runtime error 869 ms 1048576 KB Execution killed with signal 9
27 Correct 974 ms 769820 KB Output is correct
28 Correct 684 ms 195516 KB Output is correct
29 Correct 677 ms 203284 KB Output is correct
30 Correct 748 ms 331216 KB Output is correct
31 Correct 586 ms 36176 KB Output is correct
32 Correct 949 ms 709540 KB Output is correct