/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.574 MiB
#2 Accepted 3ms 2.527 MiB
#3 Accepted 3ms 2.574 MiB
#4 Accepted 3ms 2.57 MiB
#5 Accepted 4ms 2.57 MiB
#6 Accepted 7ms 3.004 MiB
#7 Time Exceeded ≥2085ms ≥35.172 MiB
#8 Time Exceeded ≥2009ms ≥35.176 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-11-11 03:50:45
Judged By
Score
60
Total Time
≥2085ms
Peak Memory
≥35.176 MiB