/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 2ms 320.0 KiB
#5 Accepted 2ms 580.0 KiB
#6 Accepted 4ms 620.0 KiB
#7 Accepted 1995ms 19.812 MiB
#8 Accepted 1998ms 19.824 MiB
#9 Time Exceeded ≥2000ms ≥19.824 MiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

void solve(int cs) {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> g(n, vector<char>(m));
  for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> g[i][j];
  vector<vector<int>> vis(n, vector<int>(m, false));
  auto isval = [&](int i, int j) -> bool {
    return i >= 0 && j >= 0 && i < n && j < m && g[i][j] == '0' && !vis[i][j];
  };
  auto f = [&](int i, int j) -> int {
    queue<array<int, 2>> Q;
    Q.push({i, j});
    int cnt = 0;
    vis[i][j] = true;
    while (Q.size()) {
      auto &[x, y] = Q.front();
      Q.pop();
      cnt += 1;
      for (auto &[dx, dy] : {pair(1, 0), pair(0, 1), pair(-1, 0), pair(0, -1)}) {
        int nx = dx + x, ny = dy + y;
        if (isval(nx, ny)) {
          Q.push({nx, ny});
          vis[nx][ny] = true;
        }
      }
    }
    return cnt;
  };
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '0') {
        if (!vis[i][j]) {
          res = max(res, f(i, j));
        }
      }
    }
  }
  cout << "Floor #" << cs << ": "<< res << "\n";
  
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-10 17:09:58
Judged At
2024-11-11 03:28:03
Judged By
Score
80
Total Time
≥2000ms
Peak Memory
≥19.824 MiB