/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 2ms 588.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 2ms 484.0 KiB
#5 Accepted 3ms 836.0 KiB
#6 Accepted 5ms 1.02 MiB
#7 Time Exceeded ≥2080ms ≥35.07 MiB
#8 Time Exceeded ≥2086ms ≥34.977 MiB
#9 Time Exceeded ≥2039ms ≥34.902 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 ; while (t--)
const int N = 2e3 + 7;
using namespace std;

int n,m,cnt=1;
queue<pair<int,int>>q;
char l[N][N];
int vis[N][N];
int dis[N][N];
int dRow[] = { -1, 0, 1, 0 };
int dCol[] = { 0, 1, 0, -1 };


bool isValid(int row, int col)
{
    if (row < 1 || col < 1 || row > n || col > m)
        return false;

    if (vis[row][col])
        return false;

    if (l[row][col]!='0')
        return false;

    return true;
}

void bfs(int x, int y)
{
    q.push({x,y});
    vis[x][y]++;
    while(!q.empty())
    {
        int u = q.front().first;
        int v = q.front().second;
        q.pop();

        for(int i=0; i<4; i++)
        {
            int adju = u+dRow[i];
            int adjv = v+dCol[i];

            if(isValid(adju,adjv))
            {
                cnt++;
                q.push({adju,adjv});
                vis[adju][adjv]++;
            }
        }
    }

}



int32_t main()
{
    ios::sync_with_stdio(false);

    int t;
    cin >> t;
    int f = 1;
    while(t--)
    {
        int ans = -1;
        cin >> n >> m;
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                cin >> l[i][j];
            }
        }
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(vis[i][j]==0 && l[i][j]=='0')
                {
                    bfs(i,j);

                }
                ans = max(ans,cnt);
                cnt = 1;
            }
        }
        cout << "Floor #" << f++ << ": " << ans << endl;
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                vis[i][j] = 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:07:05
Judged At
2024-10-03 14:10:48
Judged By
Score
60
Total Time
≥2086ms
Peak Memory
≥35.07 MiB