Submission #234272

# Submission time Handle Problem Language Result Execution time Memory
234272 2020-05-23T16:52:57 Z jungsnow Zoo (COCI19_zoo) C++14
45 / 110
2000 ms 10720 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 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 648 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 12 ms 640 KB Output is correct
9 Correct 12 ms 640 KB Output is correct
10 Correct 16 ms 640 KB Output is correct
11 Correct 14 ms 640 KB Output is correct
12 Correct 16 ms 640 KB Output is correct
13 Correct 12 ms 640 KB Output is correct
14 Correct 12 ms 640 KB Output is correct
15 Correct 12 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 648 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 12 ms 640 KB Output is correct
9 Correct 12 ms 640 KB Output is correct
10 Correct 16 ms 640 KB Output is correct
11 Correct 14 ms 640 KB Output is correct
12 Correct 16 ms 640 KB Output is correct
13 Correct 12 ms 640 KB Output is correct
14 Correct 12 ms 640 KB Output is correct
15 Correct 12 ms 640 KB Output is correct
16 Correct 29 ms 4960 KB Output is correct
17 Correct 30 ms 4952 KB Output is correct
18 Correct 28 ms 4976 KB Output is correct
19 Correct 42 ms 5200 KB Output is correct
20 Correct 30 ms 4916 KB Output is correct
21 Execution timed out 2084 ms 10720 KB Time limit exceeded
22 Halted 0 ms 0 KB -