제출 #862294

#제출 시각아이디문제언어결과실행 시간메모리
862294Truly_Tracks in the Snow (BOI13_tracks)C++14
100 / 100
488 ms122492 KiB
#define nametask "tracks" #include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define SZ(a) (int) a.size() #define FOR(i, a, b) for (int i = a; i <= b; i++) #define FOD(i, b, a) for (int i = b; i >= a; i--) using namespace std; typedef long long ll; typedef pair <int, int> pi; const pi dir[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; const int N = 4005; int n, m; char a[N][N]; int d[N][N]; bool ok(int i, int j){ return (i >= 1 && i <= n && j >= 1 && j <= m); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (fopen(nametask".inp", "r")){ freopen(nametask".inp", "r", stdin); freopen(nametask".out", "w", stdout); } cin >> n >> m; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ cin >> a[i][j]; } } for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++) d[i][j] = 0; } int ans = 1; deque <pi> dq; d[1][1] = 1; dq.push_back(mp(1, 1)); while (!dq.empty()){ pi top = dq.front(); ans = max(ans, d[top.fi][top.se]); dq.pop_front(); for (int i = 0; i < 4; i++){ int u = top.fi + dir[i].fi, v = top.se + dir[i].se; if (ok(u, v) && (a[u][v] != '.') && (d[u][v] == 0)){ if (a[u][v] == a[top.fi][top.se]){ d[u][v] = d[top.fi][top.se]; dq.push_front(mp(u, v)); } else { d[u][v] = d[top.fi][top.se] + 1; dq.push_back(mp(u, v)); } } } } cout << ans; return 0; }

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

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