/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 580.0 KiB
#2 Accepted 1ms 392.0 KiB
#3 Accepted 1ms 580.0 KiB
#4 Accepted 2ms 580.0 KiB
#5 Accepted 2ms 688.0 KiB
#6 Accepted 3ms 788.0 KiB
#7 Accepted 1486ms 8.57 MiB
#8 Accepted 1435ms 8.562 MiB
#9 Accepted 1420ms 8.574 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbg(a,b,c,d) cerr<<a<<"  "<<b<<"  "<<c<<"  "<<d<<endl;
#define kill(a) {cout<<a<<endl;continue;}
#define KILL(a) {cout<<a<<endl;return 0;}
#define debug cerr<<"Error Found"<<endl;
#define mem(a,b) memset(a,b,sizeof(a))
#define lcm(a, b) (a/__gcd(a,b))*b
#define w(t) cin>>t;while(t--)
#define pi  2 * acos(0.0)
#define endl "\n"
int t, cs = 0;
const int mxn = 2e3 + 3, mod = 1e9 + 7;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;
string str[mxn];
bool vis[mxn][mxn];
bool ok(int i, int j)
{
    return (i >= 0 and j >= 0 and i < n and j < m and !vis[i][j] and str[i][j] == '0');
}
int bfs(int r, int c)
{
    queue<pair<int,int>>q;
    q.push(make_pair(r, c));
    int space = 0;
    while(!q.empty())
    {
        int x = q.front().first, y = q.front().second;
        q.pop();
        if(vis[x][y])continue;
        vis[x][y] = true, space++;
        for(int i = 0; i < 4; i++)
        {
            int X = x + dx[i], Y = y + dy[i];
            if(ok(X, Y))q.push(make_pair(X, Y));
        }
    }
    return space;
}
void refresh(int n, int m)
{
    for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)vis[i][j] = false;
}
int32_t main()
{

    fast
    w(t)
    {
        cin >> n >> m;
        refresh(n, m);
        for(int i = 0; i < n; i++)cin >> str[i];
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(str[i][j] == '1' or vis[i][j])continue;
                ans = max(ans, bfs(i, j));
            }
        }
        cout << "Floor #" << ++cs <<": " << ans << endl;
    }
}

Information

Submit By
Type
Submission
Problem
P1002 Office Space
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-07 18:58:01
Judged At
2024-11-11 02:23:00
Judged By
Score
100
Total Time
1486ms
Peak Memory
8.574 MiB