Submission #199484

#TimeUsernameProblemLanguageResultExecution timeMemory
199484SamAndZoo (COCI19_zoo)C++17
0 / 110
2085 ms376 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1003; const int xx[4] = {0, 1, 0, -1}; const int yy[4] = {1, 0, -1, 0}; struct ban { int x, y; ban(){} ban(int x, int y) { this->x = x; this->y = y; } }; int n, m; char a[N][N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf(" %s", a[i]); if (a[0][0] == '*') { printf("0\n"); return 0; } int ans = 0; char z = a[0][0]; char hz; if (z == 'B') hz = 'T'; else hz = 'B'; queue<ban> q, qq; q.push(ban(0, 0)); a[0][0] = 'X'; while (1) { if (q.empty()) break; ++ans; while (!q.empty()) { ban t = q.front(); q.pop(); for (int i = 0; i < 4; ++i) { ban h = t; h.x += xx[i]; h.y += yy[i]; if (h.x >= 0 && h.x < n && h.y >= 0 && h.y < m) { if (a[h.x][h.y] == z) { a[h.x][h.y] = 'X'; q.push(h); } else if (a[h.x][h.y] == hz) { qq.push(h); } } } } q = qq; while (!qq.empty()) qq.pop(); swap(z, hz); } printf("%d\n", ans); return 0; }

Compilation message (stderr)

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