/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 344.0 KiB
#4 Accepted 2ms 612.0 KiB
#5 Accepted 2ms 328.0 KiB
#6 Accepted 4ms 532.0 KiB
#7 Accepted 1854ms 5.332 MiB
#8 Accepted 1800ms 5.34 MiB
#9 Accepted 1854ms 5.328 MiB

Code


#include <vector>
#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<pair<int, int>> moves = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int tt;
  cin >> tt;
  for (int tc = 1; tc <= tt; tc++) {
    cout << "Floor #" << tc << ": ";
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    vector was(n, vector<bool> (m));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (!was[i][j] && a[i][j] - '1') {
          was[i][j] = 1;
          vector<int> que(1, i * m + j);
          for (int k = 0; k < (int) que.size(); k++) {
            int x = que[k] / m;
            int y = que[k] % m;
            for (auto [u, v] : moves) {
              u += x, v += y;
              if (min(u, v) >= 0 && min(n - u, m - v) > 0 && a[u][v] - '1' && !was[u][v]) {
                was[u][v] = 1;
                que.push_back(u * m + v);
              }
            }
          }
          ans = max(ans, (int) que.size());
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
 

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 20:05:09
Judged At
2024-11-11 03:31:31
Judged By
Score
100
Total Time
1854ms
Peak Memory
5.34 MiB