/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Time Exceeded ≥2020ms ≥22.668 MiB
#2 Time Exceeded ≥2032ms ≥23.219 MiB

Code

//on the name of Allah:)
#include<bits/stdc++.h>
#define int         long long
#define endl        "\n"
#define pi          2 * acos(0.0)
#define mod         1000000007
#define Mul(a,b)    (a%mod * b%mod)%mod
#define Add(a,b)    (a%mod + b%mod)%mod
#define all(x)      (x).begin(),(x).end()
#define allr(x)     (x).rbegin(),(x).rend()
#define gcd(x, y)   (__gcd(x, y))
#define lcm(x, y)   ((x/gcd(x, y))*y)
#define faster      cin.tie(NULL), cout.tie(NULL);
#define TC   int t ; cin>>t ; for(int i=1;i<=t;i++)
using namespace std;
const int N=1000 + 9;
char g[N][N];
bool vis[N][N];
int n,m;
int cnt=0;
void dfs(int x,int y)
{
    cnt++;
    vis[x][y]=true;
    if(x-1>0 && x-1<=n && vis[x-1][y]==false && g[x-1][y]=='0' )dfs(x-1,y);
    if(x+1>0 && x+1<=n && vis[x+1][y]==false && g[x+1][y]=='0')dfs(x+1,y);
    if(y-1>0 && y-1<=m && vis[x][y-1]==false && g[x][y-1]=='0')dfs(x,y-1);
    if(y+1>0 && y+1<=m && vis[x][y+1]==false && g[x][y+1]=='0')dfs(x,y+1);


}
int32_t main()
{
//    ios::sync_with_stdio(false);
    //faster
    while(1)
    {
       int t ;
        cin>>t ;
        for(int i=1;i<=t;i++)
        {
            cin>>n>>m;
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    cin>>g[i][j];


                }
            }

            int ans=0;
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    if(g[i][j]=='0' && vis[i][j]==false)
                    {
                        dfs(i,j);
                        ans=max(ans,cnt);
                       cnt=0;

                    }
                }
            }

            for(int i=0; i<=n; i++)
            {
                for(int j=0; j<=m; j++)
                {
                    vis[i][j]=false;
                }
            }
            cout<<"Florr #"<<i<<": ";
            cout<<ans<<endl;
        }

    }





}





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:57:53
Judged At
2024-11-11 03:50:18
Judged By
Score
0
Total Time
≥2032ms
Peak Memory
≥23.219 MiB