Submission #706599

# Submission time Handle Problem Language Result Execution time Memory
706599 2023-03-07T06:29:08 Z YugiHacker Zoo (COCI19_zoo) C++14
110 / 110
65 ms 6248 KB
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn 1003
#define fi first
#define se second
using namespace std;
int n, m, d[maxn][maxn];
char a[maxn][maxn];
int x[] = {0, 0, 1, -1};
int y[] = {1, -1, 0, 0};
main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    f1 (i,n) f1 (j, m)
        cin >> a[i][j];
    memset(d, -1, sizeof(d));
    d[1][1] = 1;
    queue <pair<int, int> >q[2];
    q[0].push({1, 1});
    int cur = 0;
    int ans = 0;
    while (q[0].size() || q[1].size())
    {
        int u = q[cur].front().fi, v = q[cur].front().se;
        ans = max(ans, d[u][v]);
        q[cur].pop();
        f0 (i, 4)
        {
            int U = u + x[i];
            int V = v + y[i];
            if (a[U][V] == a[u][v] && d[U][V]==-1)
            {
                d[U][V] = d[u][v];
                q[cur].push({U,V});
            }
            if (a[U][V] == ('B'+'T'-a[u][v]) && d[U][V] == -1)
            {
                d[U][V] = d[u][v] + 1;
                q[1-cur].push({U,V});
            }
        }
        if (q[cur].size() == 0) cur ^= 1;
    }
    cout << ans;
}

Compilation message

zoo.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4164 KB Output is correct
2 Correct 3 ms 4184 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4300 KB Output is correct
6 Correct 2 ms 4292 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 3 ms 4368 KB Output is correct
9 Correct 3 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 3 ms 4308 KB Output is correct
13 Correct 2 ms 4300 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4164 KB Output is correct
2 Correct 3 ms 4184 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4300 KB Output is correct
6 Correct 2 ms 4292 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 3 ms 4368 KB Output is correct
9 Correct 3 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 3 ms 4308 KB Output is correct
13 Correct 2 ms 4300 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 19 ms 6096 KB Output is correct
17 Correct 25 ms 6100 KB Output is correct
18 Correct 20 ms 6248 KB Output is correct
19 Correct 20 ms 6176 KB Output is correct
20 Correct 18 ms 6100 KB Output is correct
21 Correct 56 ms 6052 KB Output is correct
22 Correct 56 ms 6116 KB Output is correct
23 Correct 61 ms 6136 KB Output is correct
24 Correct 65 ms 6204 KB Output is correct
25 Correct 60 ms 6100 KB Output is correct
26 Correct 57 ms 6100 KB Output is correct
27 Correct 57 ms 6116 KB Output is correct
28 Correct 56 ms 6112 KB Output is correct
29 Correct 59 ms 6192 KB Output is correct
30 Correct 58 ms 6172 KB Output is correct