/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 576.0 KiB
#2 Accepted 2ms 764.0 KiB
#3 Accepted 2ms 480.0 KiB
#4 Accepted 2ms 580.0 KiB
#5 Accepted 2ms 788.0 KiB
#6 Accepted 4ms 1.02 MiB
#7 Accepted 1468ms 19.703 MiB
#8 Accepted 1473ms 19.695 MiB
#9 Accepted 1480ms 19.699 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=1e6+10,MOD=1000000007;
typedef long long ll;
char ch[2002][2002];
int A[]={1,-1,0,0};
int B[]={0,0,1,-1};
int vis[2002][2002];
int cnt=0;
int res=0;
void dfs(int x,int y,int n,int m){
    cnt++;
    vis[x][y]=1;
    for(int i=0;i<4;i++){
        int a=A[i]+x;
        int b=B[i]+y;
        if(a>0 && a<=n && b>0 && b<=m && ch[a][b]=='0'&&!vis[a][b])
        {
             dfs(a,b,n,m);
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    int cas=1;
    while(t--){
     int n,m;
     cin>>n>>m;
     res=0;
     for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)cin>>ch[i][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            if(ch[i][j]=='0'&&!vis[i][j]){
                cnt=0;
                dfs(i,j,n,m);
                res=max(res,cnt);
            }
        }
        cout<<"Floor #"<<cas<<": ";
        cout<<res<<"\n";
        cas++;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)vis[i][j]=0;



   }
       

    
    return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Contest
Beta Round #1
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 17:08:05
Judged At
2024-11-11 03:50:45
Judged By
Score
100
Total Time
1480ms
Peak Memory
19.703 MiB