/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 636.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 1ms 540.0 KiB
#5 Accepted 2ms 540.0 KiB
#6 Accepted 3ms 584.0 KiB
#7 Accepted 1365ms 5.332 MiB
#8 Accepted 1368ms 5.348 MiB
#9 Accepted 1372ms 5.367 MiB

Code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int di[4] = {-1, 1, 0, 0};
int dj[4] = {0, 0, -1, 1};

void solve(int T) {
	int n, m; cin >> n >> m;
	vector<string> s(n);
	vector<vector<bool>> visited(n, vector<bool>(m, false));
	for(auto &x : s) cin >> x;

	int ans = 0, cnt = 0;

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(s[i][j] == '0' && !visited[i][j]) {
				queue<pair<int,int>> que;
				que.push({i,j});
				visited[i][j] = true;
				cnt = 0;
				while(!que.empty()) {
					cnt++;
					auto p = que.front();
					que.pop();
					int ti = p.first;
					int tj = p.second;
					for(int k = 0; k < 4; k++) {
						int ni = ti + di[k];
						int nj = tj + dj[k];
						if(ni < n && ni >= 0 
								&& nj < m && nj >= 0
								&& !visited[ni][nj] && s[ni][nj] == '0') {
							que.push({ni,nj});
							visited[ni][nj] = true;
						}
					}
				}

				ans = max(ans, cnt);
			}
		}
	}
	cout << "Floor #" << T << ": " << ans << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifdef MYPC
	cout << "==== OUTPUT ====\n";
#endif
	int t; cin >> t;
	for(int i = 1; i <= t; i++) {
		solve(i);
	}
}

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 13:29:47
Judged At
2025-02-17 13:29:47
Judged By
Score
100
Total Time
1372ms
Peak Memory
5.367 MiB