/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 1ms 516.0 KiB
#4 Accepted 2ms 576.0 KiB
#5 Accepted 2ms 580.0 KiB
#6 Accepted 4ms 576.0 KiB
#7 Accepted 1521ms 4.977 MiB
#8 Accepted 1535ms 4.98 MiB
#9 Accepted 1527ms 5.082 MiB

Code

#include<bits/stdc++.h>
using namespace std;
char grid[2001][2001];
//bool vis[2001][2001];
int n,m,room=0,mx=0;
bool ok=false;
void dfs(int i,int j,vector<vector<bool>> &vis)
{
    if(i<0 || j<0) return;
    if(i>=n || j>=m) return;
    if(vis[i][j]) return;
    if(grid[i][j]=='1') return;

    ++room;
    vis[i][j]=true;
    dfs(i+1,j,vis);
    dfs(i,j+1,vis);
    dfs(i-1,j,vis);
    dfs(i,j-1,vis);
}

void solve(int tc)
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) 
        {
            cin>>grid[i][j];
        }
    }
    
    vector<vector<bool>>vis(n+1,vector<bool>(m+1));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(grid[i][j]=='1' || vis[i][j]) continue;
            dfs(i,j,vis);
            mx=max(mx,room);
            room=0;
        }
    }
    
    cout<<"Floor #"<<tc<<": ";
    cout<<mx<<endl;
    mx=0;
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t; cin>>t;
    for(int i=1;i<=t;i++)
    {
        solve(i);
        /*for(int i=0;i<=2000;i++)
        {
            for(int j=0;j<=2000;j++)
            {
                vis[i][j]=false;
            }
        }*/
    }
}

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-12 08:20:09
Judged At
2024-11-11 02:37:43
Judged By
Score
100
Total Time
1535ms
Peak Memory
5.082 MiB