제출 #1000183

#제출 시각아이디문제언어결과실행 시간메모리
1000183a5a7Tracks in the Snow (BOI13_tracks)C++14
100 / 100
620 ms226492 KiB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> 
using indexedset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    char grid[n][m];
    ll dist[n][m];
    int visited[n][m];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> grid[i][j];
            dist[i][j] = 0;
            visited[i][j] = 0;
        }
    }
    deque<pair<int, int>> q;
    dist[0][0] = 1;
    q.push_back({0, 0});
    vector<pair<int, int>> dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
    ll ans = 1;
    while (!q.empty()){
        auto x = q.front();
        q.pop_front();
        ans = max(ans, dist[x.first][x.second]);
        for (auto y : dir){
            int nx = x.first + y.first;
            int ny = x.second + y.second;
            if (nx < 0 || ny < 0 || nx >= n || ny >= m) continue;
            if (grid[nx][ny] == '.') continue;
            if (dist[nx][ny] != 0) continue;
            if (grid[nx][ny] == grid[x.first][x.second]){
                dist[nx][ny] = dist[x.first][x.second];
                q.push_front({nx, ny});
            }else{
                dist[nx][ny] = dist[x.first][x.second]+1;
                q.push_back({nx, ny});
            }
        }
    }
    cout << ans << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:16:9: warning: variable 'visited' set but not used [-Wunused-but-set-variable]
   16 |     int visited[n][m];
      |         ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...