Submission #478656

# Submission time Handle Problem Language Result Execution time Memory
478656 2021-10-08T06:27:48 Z Neos Zoo (COCI19_zoo) C++14
110 / 110
80 ms 6232 KB
#include <bits/stdc++.h>
using namespace std;
const int tx[4]={0,0,1,-1};
const int ty[4]={1,-1,0,0};
typedef pair<int, int> super;
typedef long long int ll;
#define pu push
bool kt[1005][1005];
int a[1005][1005],n,m,rx,ry;
void bfs(int x,int y)
{
    queue<super> p;
    p.pu({x,y});
    kt[x][y]=true;
    ll count1=0;
    while (!p.empty())
    {
    queue <super> p1;
    while (!p.empty())
    {
        x=p.front().first;
        y=p.front().second;
        p.pop();
        for (int i=0;i<4;i++)
        {
            rx=x+tx[i];
            ry=y+ty[i];
            if (!kt[rx][ry] && a[rx][ry]!=0)
                if (a[rx][ry]==a[x][y])
                {
                    kt[rx][ry]=true;
                    p.pu({rx,ry});
                }
                else
                {
                    kt[rx][ry]=true;
                    p1.pu({rx,ry});
                }
        }
    }
    count1++;
    p=p1;
    }
    cout<<count1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("animal.inp","r",stdin);
    //freopen("animal.out","w",stdout);
    cin>>n>>m;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            char x;
            cin>>x;
            if (x=='T') a[i][j]=1;
            if (x=='B') a[i][j]=2;
        }
    bfs(1,1);
    return 0;
}

Compilation message

zoo.cpp: In function 'void bfs(int, int)':
zoo.cpp:28:16: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   28 |             if (!kt[rx][ry] && a[rx][ry]!=0)
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 580 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 1 ms 840 KB Output is correct
8 Correct 1 ms 720 KB Output is correct
9 Correct 1 ms 720 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 1 ms 720 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 1 ms 720 KB Output is correct
15 Correct 1 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 580 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 1 ms 840 KB Output is correct
8 Correct 1 ms 720 KB Output is correct
9 Correct 1 ms 720 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 1 ms 720 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 1 ms 720 KB Output is correct
15 Correct 1 ms 720 KB Output is correct
16 Correct 23 ms 6188 KB Output is correct
17 Correct 23 ms 6088 KB Output is correct
18 Correct 23 ms 6168 KB Output is correct
19 Correct 23 ms 6220 KB Output is correct
20 Correct 20 ms 6096 KB Output is correct
21 Correct 65 ms 5928 KB Output is correct
22 Correct 65 ms 5936 KB Output is correct
23 Correct 66 ms 5940 KB Output is correct
24 Correct 80 ms 6232 KB Output is correct
25 Correct 67 ms 6092 KB Output is correct
26 Correct 68 ms 6064 KB Output is correct
27 Correct 67 ms 5984 KB Output is correct
28 Correct 65 ms 5856 KB Output is correct
29 Correct 68 ms 6088 KB Output is correct
30 Correct 69 ms 6072 KB Output is correct