제출 #1305634

#제출 시각아이디문제언어결과실행 시간메모리
1305634tkvinhtruongquangTracks in the Snow (BOI13_tracks)C++20
19.79 / 100
635 ms191168 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define pf push_front #define sz(x) int(x.size()) #define all(x) x.begin(), x.end() #define clz __builtin_clz #define popcount __builtin_popcount #define lb(x) lower_bound(x) #define ub(x) upper_bound(x) #define loop(i, j, n, k) for(int i = j; i <= n; i += k) #define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0) template <typename T> inline void print(T x) { cerr << x << endl; } template <typename T> inline void print(vector <T> x) { cerr << '['; loop(i, 0, sz(x) - 2, 1) cerr << x[i] << ", "; cerr << x.back() << ']' << endl; } template <typename T> inline bool maximize(T &a, const T &b) { return a < b ? (a = b) : 0; } template <typename T> inline bool minimize(T &a, const T &b) { return a > b ? (a = b) : 0; } using ll = long long; using vi = vector<int>; using pii = pair<int, int>; using pss = pair<string, string>; using vll = vector<ll>; using pll = pair<ll, ll>; #define debug(x) cerr << #x << " = "; print(x) mt19937 rng(chrono :: steady_clock :: now().time_since_epoch().count()); template <typename T> inline int rand_range(T l, T r) { return uniform_int_distribution<T> (l, r)(rng); } void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); freopen("error.txt", "w", stderr); } int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { // setIO("task"); fast; int n, m; cin >> n >> m; vector<vi> matrix(n + 5, vi(m + 5, 0)); loop(i, 1, n, 1) { loop(j, 1, m, 1) { char c; cin >> c; matrix[i][j] = (c == 'R' ? 1 : 2); } } if(matrix[1][1] == 0) { return cout << 0, 0; } auto valid = [&](int x, int y) -> bool { return x <= n && y <= m && matrix[x][y] > 0; }; vector<vi> dist(n + 5, vi(m + 5, 0)); deque<pii> dq; dq.pb({1, 1}); dist[1][1] = 1; int ans = 0; while(sz(dq)) { auto [x, y] = dq.front(); dq.pop_front(); ans = max(ans, dist[x][y]); loop(i, 0, 3, 1) { int nx = x + dx[i]; int ny = y + dy[i]; if(valid(nx, ny) && !dist[nx][ny]) { if(matrix[nx][ny] == matrix[x][y]) { dist[nx][ny] = dist[x][y]; dq.pf({nx, ny}); } else { dist[nx][ny] = dist[x][y] + 1; dq.pb({nx, ny}); } } } } cout << ans; }

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

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