Submission #706599

#TimeUsernameProblemLanguageResultExecution timeMemory
706599YugiHackerZoo (COCI19_zoo)C++14
110 / 110
65 ms6248 KiB
#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 (stderr)

zoo.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...