제출 #751985

#제출 시각아이디문제언어결과실행 시간메모리
751985cwzaTracks in the Snow (BOI13_tracks)C++17
100 / 100
1022 ms147836 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
 
void IO(string name = "") {
	cin.tie(0)->sync_with_stdio(0);
	if (name.size()) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}
 
const int inf = 1e9+7;
vector<string> grid;
int H, W;
 
bool is_valid(int row, int col) {
    if(row>=0 && row<H && col>=0 && col<W && grid[row][col]!='.') return true;
    return false;
}
 
int main() {
    // IO("pcb");
 
    cin >> H >> W;
    grid.resize(H);
    for(int i = 0; i < H; i++) cin >> grid[i];
 
    vector<vector<int>> dist(H, vector<int>(W, inf));
    dist[0][0] = 0;
    deque<tuple<int,int,int>> dq; // d, row, col
    dq.push_back({0, 0, 0});
    while(dq.size()) {
        auto [d, row, col] = dq.front(); dq.pop_front();
        if(d>dist[row][col]) continue;
        pair<int,int> dirs[] = {{0,1},{0,-1},{1,0},{-1,0}};
        for(auto[dirrow, dircol] : dirs) {
            int nrow = row + dirrow;
            int ncol = col + dircol;
            if(is_valid(nrow, ncol)) {
                if(grid[row][col]==grid[nrow][ncol]) { // 0
                    if(dist[row][col]+0<dist[nrow][ncol]) {
                        dist[nrow][ncol] = dist[row][col]+0;
                        dq.push_front({dist[nrow][ncol], nrow, ncol});
                    }
                } else { // 1
                    if(dist[row][col]+1<dist[nrow][ncol]) {
                        dist[nrow][ncol] = dist[row][col]+1;
                        dq.push_back({dist[nrow][ncol], nrow, ncol});
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(dist[i][j]<inf) {
                ans = max(ans, dist[i][j]);
            }
        }
    }
    cout << ans+1;
}

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

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