제출 #1279913

#제출 시각아이디문제언어결과실행 시간메모리
1279913ducanh0811Tracks in the Snow (BOI13_tracks)C++20
4.38 / 100
1539 ms934116 KiB
#include <bits/stdc++.h> #define int long long #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define REV(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) using namespace std; int n, m; #define MAXN 4005 char a[MAXN][MAXN]; const int dx[] = {0, 1, 0, -1}; const int dy[] = {-1, 0, 1, 0}; bool start[MAXN][MAXN]; bool vi[MAXN][MAXN]; int group = 0; bool valid(int i, int j){ return (i >= 1 && i <= n && j >= 1 && j <= m); } void DFS(int i, int j){ start[i][j] = 1; FOR(k, 0, 3){ int ii = i + dy[k]; int jj = j + dx[k]; if (valid(ii, jj) && a[ii][jj] == a[1][1] && start[ii][jj] == 0){ DFS(ii, jj); } } } void dfs(int i, int j){ vi[i][j] = 1; FOR(k, 0, 3){ int ii = i + dy[k]; int jj = j + dx[k]; if (valid(ii, jj) && !vi[ii][jj] && (a[ii][jj] == a[i][j] || start[ii][jj] || start[i][j])){ dfs(ii, jj); } } } void solve(){ cin >> n >> m; FOR(i, 1, n){ FOR(j, 1, m){ cin >> a[i][j]; } } DFS(1, 1); // FOR(i, 1, n){ // FOR(j, 1, m){ // cout << start[i][j]; // } // cout << '\n'; // } FOR(i, 1, n){ FOR(j, 1, m){ if (vi[i][j]) continue; group++; dfs(i, j); } } int ok = 0; FOR(i, 1, n){ FOR(j, 1, m){ if (start[i][j]){ FOR(k, 0, 3){ int ii = i + dy[k]; int jj = j + dx[k]; if (valid(ii, jj) && a[ii][jj] != '.' && a[ii][jj] != a[i][j]) ok = 1; } } } } cout << group + ok; } #define task "test" int32_t main(){ if (fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); return 0; }

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

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