제출 #1291218

#제출 시각아이디문제언어결과실행 시간메모리
1291218jim_xTracks in the Snow (BOI13_tracks)C++17
100 / 100
613 ms110684 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;

void baseIO(string s = ""){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (s.size()){
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}

vector<pair<int, int>> change = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main() {
    baseIO();

    int h, w;
    cin >> h >> w;
    char grid[h][w];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++) cin >> grid[i][j];
    }

    vector<vector<int>> dist(h, vector<int>(w, 0));
    dist[0][0] = 1;
    deque<pair<int, int>> q;
    q.push_front({0, 0});
    while (!q.empty()) {
        pair<int, int> c = q.front();
        q.pop_front();
        for (auto chg : change){
            int nx = c.first + chg.first, ny = c.second + chg.second;
            if (0 <= nx && nx < h && 0 <= ny && ny < w && grid[nx][ny] != '.' && dist[nx][ny] == 0){
                if (grid[c.first][c.second] == grid[nx][ny]){
                    dist[nx][ny] = dist[c.first][c.second];
                    q.push_front({nx, ny});
                }else{
                    dist[nx][ny] = dist[c.first][c.second] + 1;
                    q.push_back({nx, ny});
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (dist[i][j] != 1e9) ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;

    return 0;
}

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

tracks.cpp: In function 'void baseIO(std::string)':
tracks.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...