제출 #490325

#제출 시각아이디문제언어결과실행 시간메모리
490325XIITracks in the Snow (BOI13_tracks)C++17
100 / 100
548 ms160124 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second #define mp make_pair #define eb emplace_back #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORU(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define IOS cin.tie(0)->sync_with_stdio(false); #define PROB "BOI13_tracks" void Fi(){ if(fopen(PROB".inp", "r")){ freopen(PROB".inp", "r", stdin); freopen(PROB".out", "w", stdout); } } const int N = 4e3 + 1; int a[N][N], n, m; int d[N][N]; int encode(const char &c){ switch(c){ case '.': return 0; case 'F': return 1; case 'R': return -1; } } const int dx[] = {0, 0, -1, +1}; const int dy[] = {-1, +1, 0, 0}; using pi = pair<int, int>; deque<pi> dq; void bfs(const pi &s){ dq.push_back(s); d[s.fi][s.se] = 1; while(!dq.empty()){ auto [x, y] = dq.front(); dq.pop_front(); FOR(direc, 0, 4){ int i = x + dx[direc]; int j = y + dy[direc]; if(i < 1 || n < i || j < 1 || m < j) continue; if(!a[i][j] || d[i][j]) continue; if(a[i][j] != a[x][y]){ d[i][j] = d[x][y] + 1; dq.push_back({i, j}); } else{ d[i][j] = d[x][y]; dq.push_front({i, j}); } } } } int main(){ IOS; Fi(); cin >> n >> m; FORU(i, 1, n){ string s; cin >> s; FORU(j, 1, m){ a[i][j] = encode(s[j - 1]); } } bfs({1, 1}); int ans = 0; FORU(i, 1, n) FORU(j, 1, m) ans = max(ans, d[i][j]); cout << ans; return 0; }

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

tracks.cpp: In function 'void Fi()':
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(PROB".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(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp: In function 'int encode(const char&)':
tracks.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...