/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 2.527 MiB
#2 Accepted 2ms 2.57 MiB
#3 Accepted 3ms 2.559 MiB
#4 Accepted 3ms 2.566 MiB
#5 Accepted 3ms 2.656 MiB
#6 Accepted 5ms 2.527 MiB
#7 Time Exceeded ≥2006ms ≥19.734 MiB
#8 Accepted 1971ms 19.723 MiB
#9 Accepted 1956ms 19.723 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ff       first
#define ss       second
#define MX       1000005
#define mod      1000000007
#define ll       long long
#define pb       push_back
#define pll      pair<ll,ll>
#define endl     "\n"
#define bug(a)   cerr<<#a<<" : "<<a<<endl
#define all(x)   (x).begin(),(x).end()
#define allr(x)  (x).rbegin(),(x).rend()
#define Mul(a,b) (a%mod * b%mod)%mod
#define Add(a,b) (a%mod + b%mod)%mod

ll n, m;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int vis[2005][2005];
char grid[2005][2005];
int cnt = 0;

void dfs(int sx, int sy) {
    cnt++;
    vis[sx][sy] = 1;
    for(int i=0; i<4; i++) {
        int x=dx[i]+sx;
        int y=dy[i]+sy;
        if(x>=0 && x<n && y>=0 && y<m && !vis[x][y] && grid[x][y]=='0')
            dfs(x,y);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll t;
    cin>>t;
    for(int tc=1; tc<=t; tc++) {

        cin>>n>>m;
        for(int i=0; i<n; i++) {
            for(int j=0; j<m; j++) {
                cin>>grid[i][j];
                vis[i][j]=0;
            }
        }


        int mx = 0;
        for(int i=0; i<n; i++) {
            for(int j=0; j<m; j++) {
                if(!vis[i][j] && grid[i][j]=='0') {
                    cnt = 0;
                    dfs(i, j);
                    mx = max(mx, cnt);
                }
            }
        }

        cout<<"Floor #"<<tc<<": "<<mx<<endl;
    }

    return 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 16:44:27
Judged At
2024-11-11 03:50:51
Judged By
Score
90
Total Time
≥2006ms
Peak Memory
≥19.734 MiB