Submission #198303

#TimeUsernameProblemLanguageResultExecution timeMemory
198303ZwariowanyMarcinZoo (COCI19_zoo)C++14
110 / 110
74 ms8180 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define ss(x) (int) x.size() #define pb push_back #define LL long long #define ld double #define cat(x) cerr << #x << " = " << x << endl #define FOR(i, j, n) for(int i = j; i <= n; ++i) #define boost cin.tie(0), ios_base::sync_with_stdio(0); using namespace std; const int nax = 1010; int n, m; char s[nax][nax]; int t[nax][nax]; bool odw[nax][nax]; vector <pair<int, int>> special, all; bool in(int r, int c) { return 1 <= r && r <= n && 1 <= c && c <= m; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int znak; void dfs(int r, int c) { odw[r][c] = 1; all.pb(mp(r, c)); for (int g = 0; g < 4; ++g) { int nr = r + dx[g]; int nc = c + dy[g]; if (!in(nr, nc) || t[nr][nc] != znak || odw[nr][nc]) continue; dfs(nr, nc); } } int main() { scanf ("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf ("%s", s[i] + 1); for (int j = 1; j <= m; ++j) { if (s[i][j] == '*') t[i][j] = 2; else t[i][j] = (s[i][j] == 'T'); } } special.pb(mp(1, 1)); int ans = 0; while (true) { if (special.empty()) break; ans++; znak = t[special[0].fi][special[0].se]; all.clear(); for (auto it : special) if (!odw[it.fi][it.se]) dfs(it.fi, it.se); special.clear(); for (auto it : all) for (int g = 0; g < 4; ++g) { int nr = it.fi + dx[g]; int nc = it.se + dy[g]; if (!in(nr, nc) || (znak != (t[nr][nc] ^ 1)) || odw[nr][nc]) continue; special.pb(mp(nr, nc)); } } printf ("%d\n", ans); return 0; }

Compilation message (stderr)

zoo.cpp: In function 'int main()':
zoo.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &m);
  ~~~~~~^~~~~~~~~~~~~~~~
zoo.cpp:49:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%s", s[i] + 1);
   ~~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...