Submission #747286

# Submission time Handle Problem Language Result Execution time Memory
747286 2023-05-24T03:55:35 Z Trunkty Zoo (COCI19_zoo) C++14
110 / 110
108 ms 69220 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int r,c,ans;
char arr[1005][1005];
vector<vector<int>> bfs[1000005];
int best[1005][1005];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> r >> c;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin >> arr[i][j];
        }
    }
    best[1][1] = 1;
    bfs[1].push_back({1,1});
    for(int i=1;i<=r*c;i++){
        if(bfs[i].size()>0){
            ans = i;
        }
        for(int j=0;j<bfs[i].size();j++){
            int x = bfs[i][j][0], y = bfs[i][j][1];
            if(x!=1 and arr[x-1][y]!='*' and !best[x-1][y]){
                if(arr[x-1][y]!=arr[x][y]){
                    best[x-1][y] = best[x][y]+1;
                    bfs[best[x-1][y]].push_back({x-1,y});
                }
                else{
                    best[x-1][y] = best[x][y];
                    bfs[best[x-1][y]].push_back({x-1,y});
                }
            }
            if(x!=r and arr[x+1][y]!='*' and !best[x+1][y]){
                if(arr[x+1][y]!=arr[x][y]){
                    best[x+1][y] = best[x][y]+1;
                    bfs[best[x+1][y]].push_back({x+1,y});
                }
                else{
                    best[x+1][y] = best[x][y];
                    bfs[best[x+1][y]].push_back({x+1,y});
                }
            }
            if(y!=1 and arr[x][y-1]!='*' and !best[x][y-1]){
                if(arr[x][y-1]!=arr[x][y]){
                    best[x][y-1] = best[x][y]+1;
                    bfs[best[x][y-1]].push_back({x,y-1});
                }
                else{
                    best[x][y-1] = best[x][y];
                    bfs[best[x][y-1]].push_back({x,y-1});
                }
            }
            if(y!=c and arr[x][y+1]!='*' and !best[x][y+1]){
                if(arr[x][y+1]!=arr[x][y]){
                    best[x][y+1] = best[x][y]+1;
                    bfs[best[x][y+1]].push_back({x,y+1});
                }
                else{
                    best[x][y+1] = best[x][y];
                    bfs[best[x][y+1]].push_back({x,y+1});
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Compilation message

zoo.cpp: In function 'int main()':
zoo.cpp:26:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for(int j=0;j<bfs[i].size();j++){
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 12 ms 23812 KB Output is correct
3 Correct 13 ms 23888 KB Output is correct
4 Correct 12 ms 24148 KB Output is correct
5 Correct 13 ms 24620 KB Output is correct
6 Correct 13 ms 24652 KB Output is correct
7 Correct 14 ms 24660 KB Output is correct
8 Correct 14 ms 24700 KB Output is correct
9 Correct 13 ms 24656 KB Output is correct
10 Correct 15 ms 24728 KB Output is correct
11 Correct 12 ms 24660 KB Output is correct
12 Correct 13 ms 24788 KB Output is correct
13 Correct 13 ms 24612 KB Output is correct
14 Correct 13 ms 24584 KB Output is correct
15 Correct 13 ms 24532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 12 ms 23812 KB Output is correct
3 Correct 13 ms 23888 KB Output is correct
4 Correct 12 ms 24148 KB Output is correct
5 Correct 13 ms 24620 KB Output is correct
6 Correct 13 ms 24652 KB Output is correct
7 Correct 14 ms 24660 KB Output is correct
8 Correct 14 ms 24700 KB Output is correct
9 Correct 13 ms 24656 KB Output is correct
10 Correct 15 ms 24728 KB Output is correct
11 Correct 12 ms 24660 KB Output is correct
12 Correct 13 ms 24788 KB Output is correct
13 Correct 13 ms 24612 KB Output is correct
14 Correct 13 ms 24584 KB Output is correct
15 Correct 13 ms 24532 KB Output is correct
16 Correct 38 ms 35328 KB Output is correct
17 Correct 38 ms 35992 KB Output is correct
18 Correct 38 ms 35392 KB Output is correct
19 Correct 42 ms 37920 KB Output is correct
20 Correct 39 ms 36044 KB Output is correct
21 Correct 102 ms 67020 KB Output is correct
22 Correct 100 ms 66920 KB Output is correct
23 Correct 97 ms 67436 KB Output is correct
24 Correct 108 ms 69220 KB Output is correct
25 Correct 107 ms 68388 KB Output is correct
26 Correct 103 ms 67788 KB Output is correct
27 Correct 102 ms 66996 KB Output is correct
28 Correct 100 ms 66760 KB Output is correct
29 Correct 108 ms 68856 KB Output is correct
30 Correct 106 ms 68252 KB Output is correct