제출 #766909

#제출 시각아이디문제언어결과실행 시간메모리
766909tamyteTracks in the Snow (BOI13_tracks)C++14
100 / 100
534 ms76184 KiB
#include<bits/stdc++.h> using namespace std; void setIO(string name = "") { cin.tie(0)->sync_with_stdio(0); // see /general/fast-io if (name.size()) { freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output freopen((name + ".out").c_str(), "w", stdout); } } int n, m; bool ok(int i, int j) { return min(i, j) >= 0 && i < n && j < m; } void solve() { cin >> n >> m; vector<vector<char>> arr(n, vector<char>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> arr[i][j]; } } vector<vector<bool>> vis(n, vector<bool>(m)); int cnt = 1; deque<pair<int, int>> dq; dq.push_front({0, 0}); vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0}; char now = arr[0][0]; while (dq.size()) { auto c = dq.front(); dq.pop_front(); if (arr[c.first][c.second] != now) { now = arr[c.first][c.second]; cnt++; } for (int i = 0; i < 4; ++i) { int ii = dy[i] + c.first; int jj = dx[i] + c.second; if (!ok(ii, jj) || vis[ii][jj] || arr[ii][jj] == '.') continue; vis[ii][jj] = true; if (arr[ii][jj] != now) { dq.push_back({ii, jj}); } else { dq.push_front({ii, jj}); } } } cout << cnt << "\n"; } int main () { setIO(); int t = 1; // cin >> t; while (t--) { solve(); } }

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

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