제출 #1135443

#제출 시각아이디문제언어결과실행 시간메모리
1135443neowamiTracks in the Snow (BOI13_tracks)C++20
100 / 100
631 ms119020 KiB
#include <bits/stdc++.h> // NeOWami using namespace std; #define ft first #define sc second using pii = pair<int, int>; const int N = 4005; const int inf = 1e9; int n, m, ans = 0; char c[N][N]; int dist[N][N]; int Dx[] = {1, -1, 0, 0}, Dy[] = {0, 0, -1, 1}; bool ckmin(int &u, int v) { if (u > v) return u = v, 1; return 0; } signed main() { cin.tie(NULL)->sync_with_stdio(false); if(ifstream("Input.inp")) { freopen("Input.inp", "r", stdin); freopen("Output.out", "w", stdout); } cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; dist[i][j] = inf; } } dist[1][1] = 1; deque<pii> dq; dq.push_back({1, 1}); while(!dq.empty()) { int x = dq.back().ft, y = dq.back().sc; dq.pop_back(); ans = max(ans, dist[x][y]); for (int mov = 0; mov < 4; mov++) { int tx = x + Dx[mov], ty = y + Dy[mov]; if (!tx || !ty || tx > n || ty > m || c[tx][ty] == '.') continue; if (c[tx][ty] == c[x][y] && ckmin(dist[tx][ty], dist[x][y])) dq.push_back({tx, ty}); if (c[tx][ty] != c[x][y] && ckmin(dist[tx][ty], dist[x][y] + 1)) dq.push_front({tx, ty}); } } cout << ans; return 0; }

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

tracks.cpp: In function 'int main()':
tracks.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("Input.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("Output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...