/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 2ms 540.0 KiB
#4 Accepted 2ms 768.0 KiB
#5 Accepted 2ms 540.0 KiB
#6 Accepted 4ms 792.0 KiB
#7 Accepted 1784ms 5.051 MiB
#8 Accepted 1747ms 5.078 MiB
#9 Accepted 1747ms 5.043 MiB

Code

// Author: Gourav Preet Gupta
// Language: C++

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define float long double
#define yes  cout << "YES" << endl;
#define no  cout << "NO" << endl;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define PI 3.141592653589793
#define Mod 1000000007

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef priority_queue<ll> pq;
typedef priority_queue<pair<ll,ll> > pqp;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

/*
****************************************LOVE YOU MAA***************************************************
**********************************FAMILY ABOVE ALL*****************************************************
**************************************GIVE ME SOME SUNSHINE , GIVE ME SOME RAIN************************
******************************GIVE ME ANOTHER CHANCE , I WANNA GROW UP ONCE AGAIN**********************
**************************************YE DIL MAANGE MORE***********************************************
**************************SHAURYAM DAKSHAM YUDDHE,BALIDAAN PARAM DHARMA********************************
*/

// Never Stop Trying.
// Trying to be Better than Myself.
 
// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

//Remember,mazaa journey mein jyaada hai,manzil main utna nahi....

const int N=1e5+5;

int row[4]={0,0,1,-1};
int col[4]={1,-1,0,0};

bool check(ll n, ll m, ll i, ll j)
{
    return (i>=0 && i<n && j>=0 && j<m);
}

void solve()
{
    ll Tc;
    cin>>Tc;
    for(ll x=1; x<=Tc; x++)
    {
        ll n,m;
        cin>>n>>m;
        vvc v(n,vc(m));
        for(ll i=0; i<n; i++)
        {
            for(ll j=0; j<m; j++)
            {
                cin>>v[i][j];
            }
        }
        ll ans = 0ll;
        vvb vis(n,vb(m,0));
        for(ll i=0; i<n; i++)
        {
            for(ll j=0; j<m; j++)
            {
                if(v[i][j]=='0' && !vis[i][j])
                {
                    ll cnt = 0ll;
                    vis[i][j]=1;
                    queue<pair<ll,ll> >q;
                    q.push({i,j});
                    while(!q.empty())
                    {
                        pair<ll,ll> p = q.front();
                        q.pop();
                        cnt++;

                        ll r = p.first;
                        ll c = p.second;
                        for(ll k=0; k<4; k++)
                        {
                            if(check(n,m,r+row[k],c+col[k]) && !vis[r+row[k]][c+col[k]] && v[r+row[k]][c+col[k]]=='0')
                            {
                                q.push({r+row[k],c+col[k]});
                                vis[r+row[k]][c+col[k]]=1;
                            }
                        }
                    }

                    // cout<<cnt<<endl;
                    ans = max(ans,cnt);
                }
            }
        }
        cout<<"Floor #"<<x<<": "<<ans<<endl;
    }
}

int main()
{    
    IOS;
    
    solve();

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 10:20:55
Judged At
2025-01-02 10:20:55
Judged By
Score
100
Total Time
1784ms
Peak Memory
5.078 MiB