/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 5ms 4.316 MiB
#2 Accepted 5ms 4.363 MiB
#3 Accepted 5ms 4.309 MiB
#4 Accepted 5ms 4.336 MiB
#5 Accepted 5ms 4.273 MiB
#6 Accepted 7ms 4.746 MiB
#7 Accepted 1028ms 8.207 MiB
#8 Accepted 1034ms 8.203 MiB
#9 Accepted 1010ms 8.195 MiB

Code

#include <iostream>
#include <cstring>
using namespace std;

int t, n, m, cs, ans, c;
char s[2005][2005];
bool f[2005][2005];


void dfs(int x, int y) {
    if (x < 0 || y < 0 || x >= m || y >= n || s[x][y] == '1' || f[x][y]) return;
    f[x][y] = 1;
    c++;
    dfs(x + 1, y);
    dfs(x - 1, y);
    dfs(x, y + 1);
    dfs(x, y - 1);
}

int main() {

    scanf("%d", &t);

    for (cs = 1; cs <= t; cs++) {
    
        scanf("%d %d", &m, &n);


        for (int i = 0; i < m; i++) {
            scanf("%s", s[i]);
        }

        memset(f, 0, sizeof f);

        ans = 0;        

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (s[i][j] == '0' && f[i][j] == 0) {
                    c = 0;
                    dfs(i, j);
                    ans = max(ans, c);
                }
            } 
        }

        printf("Floor #%d: %d\n", cs, ans);

    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-22 20:31:54
Judged At
2024-11-11 03:51:35
Judged By
Score
100
Total Time
1034ms
Peak Memory
8.207 MiB