답안 #1089517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089517 2024-09-16T15:45:32 Z Hora000 Zoo (COCI19_zoo) C++14
110 / 110
42 ms 7260 KB
#include<iostream>
#include<vector>
#include<deque>
#include<array>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> a(n + 2);
    string c = "";
    for(int i = 0; i <= m + 1; i++) c += "*";
    a[0] = c; 
    a[n + 1] = c;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] = "*" + a[i] + "*";
    }
    vector<vector<int>> b(n + 2, vector<int>(m + 2, -1));
    deque<array<int, 2>> dq;
    b[1][1] = 1;
    int maxi = 1;
    dq.push_back({1, 1});
    vector<array<int, 2>> dir = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
    while(!dq.empty()){
        int x = dq.front()[0];
        int y = dq.front()[1];
        dq.pop_front();
        for(auto d : dir){
            int xd = x + d[0];
            int yd = y + d[1];
            if(b[xd][yd] == -1){
                if(a[x][y] == a[xd][yd]){
                    dq.push_front({xd, yd});
                    b[xd][yd] = b[x][y];
                }
                else if(a[xd][yd] != '*'){
                    dq.push_back({xd, yd});
                    b[xd][yd] = b[x][y] + 1;
                    maxi = b[x][y] + 1;
                }
            }
        }
    }
    cout << maxi << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 20 ms 7144 KB Output is correct
17 Correct 18 ms 7004 KB Output is correct
18 Correct 18 ms 7260 KB Output is correct
19 Correct 19 ms 7244 KB Output is correct
20 Correct 17 ms 7000 KB Output is correct
21 Correct 41 ms 6748 KB Output is correct
22 Correct 40 ms 6744 KB Output is correct
23 Correct 40 ms 6748 KB Output is correct
24 Correct 40 ms 7004 KB Output is correct
25 Correct 39 ms 7084 KB Output is correct
26 Correct 41 ms 7004 KB Output is correct
27 Correct 39 ms 6748 KB Output is correct
28 Correct 40 ms 6748 KB Output is correct
29 Correct 42 ms 7004 KB Output is correct
30 Correct 42 ms 6916 KB Output is correct