# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
198011 |
2020-01-24T13:14:50 Z |
model_code |
Zoo (COCI19_zoo) |
C++17 |
|
2000 ms |
9436 KB |
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
typedef long long llint;
const int MAXN = 1010;
bool bio[MAXN][MAXN];
char grid[MAXN][MAXN];
int R, S, cnt;
int dr[] = {1, 0, -1, 0};
int ds[] = {0, 1, 0, -1};
vector<pair<int, int>> comp;
inline char other(char c) {
if (c == 'T') return 'B';
return 'T';
}
inline bool check(int r, int s) {
return r >= 0 && r < R && s >= 0 && s < S && grid[r][s] == grid[0][0] &&
!bio[r][s];
}
int floodfill() {
queue<pair<int, int>> Q;
vector<pair<int, int>> v;
Q.push({0, 0});
bio[0][0] = true;
while (!Q.empty()) {
auto curr = Q.front();
Q.pop();
v.push_back(curr);
for (int i = 0; i < 4; ++i) {
int r = curr.first + dr[i], s = curr.second + ds[i];
if (check(r, s)) {
bio[r][s] = true;
Q.push({r, s});
}
}
}
char c = other(grid[0][0]);
for (auto &p : v) {
grid[p.first][p.second] = c;
bio[p.first][p.second] = false;
}
return v.size();
}
int main(void) {
scanf("%d%d", &R, &S);
for (int i = 0; i < R; ++i) {
scanf("%s", grid[i]);
for (int j = 0; j < S; ++j)
cnt += grid[i][j] != '*';
}
int sol = 1;
while (floodfill() < cnt) ++sol;
printf("%d\n", sol);
return 0;
}
Compilation message
zoo.cpp: In function 'int main()':
zoo.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &R, &S);
~~~~~^~~~~~~~~~~~~~~~
zoo.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", grid[i]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
11 ms |
636 KB |
Output is correct |
9 |
Correct |
11 ms |
632 KB |
Output is correct |
10 |
Correct |
13 ms |
632 KB |
Output is correct |
11 |
Correct |
13 ms |
632 KB |
Output is correct |
12 |
Correct |
16 ms |
632 KB |
Output is correct |
13 |
Correct |
11 ms |
632 KB |
Output is correct |
14 |
Correct |
10 ms |
636 KB |
Output is correct |
15 |
Correct |
12 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
11 ms |
636 KB |
Output is correct |
9 |
Correct |
11 ms |
632 KB |
Output is correct |
10 |
Correct |
13 ms |
632 KB |
Output is correct |
11 |
Correct |
13 ms |
632 KB |
Output is correct |
12 |
Correct |
16 ms |
632 KB |
Output is correct |
13 |
Correct |
11 ms |
632 KB |
Output is correct |
14 |
Correct |
10 ms |
636 KB |
Output is correct |
15 |
Correct |
12 ms |
632 KB |
Output is correct |
16 |
Correct |
30 ms |
3888 KB |
Output is correct |
17 |
Correct |
32 ms |
4036 KB |
Output is correct |
18 |
Correct |
29 ms |
3904 KB |
Output is correct |
19 |
Correct |
44 ms |
4184 KB |
Output is correct |
20 |
Correct |
32 ms |
3860 KB |
Output is correct |
21 |
Execution timed out |
2066 ms |
9436 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |