/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 2ms 580.0 KiB
#5 Accepted 2ms 576.0 KiB
#6 Accepted 5ms 532.0 KiB
#7 Time Exceeded ≥2081ms ≥4.953 MiB
#8 Time Exceeded ≥2094ms ≥4.949 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++)
        {
            dfs(i,j,vis);
            mx=max(mx,room);
            room=0;
        }
    }
    
    cout<<"Floor #"<<tc<<": ";
    cout<<mx<<endl;
    mx=0;
}

int main()
{
    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++20 (G++ 13.2.0)
Submit At
2024-02-07 08:33:53
Judged At
2024-11-11 03:43:16
Judged By
Score
60
Total Time
≥2094ms
Peak Memory
≥4.953 MiB