Submission #52854959


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(l);i>=(r);--i)
#define repn(i,n) for(int i=0;i<(n);++i)
#define sizc(x) ((int)x.size())
#define allc(x) x.begin(),x.end()
#define fir first
#define sec second
namespace KnownError_{
constexpr int N = 1005;
int n,m;
bool ok[N][N],st[N][N];
bool vis[N][N];
int ans=1;
unordered_set<int> se;
int id(int x,int y){return x*m+y;}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(l);i>=(r);--i)
#define repn(i,n)  for(int i=0;i<(n);++i)
#define sizc(x) ((int)x.size())
#define allc(x) x.begin(),x.end()
#define fir first
#define sec second
namespace KnownError_{
    constexpr int N = 1005;
    int n,m;
    bool ok[N][N],st[N][N];
    bool vis[N][N];
    int ans=1;
    unordered_set<int> se;
    int id(int x,int y){return x*m+y;}
    void dfs(int x,int y){
        se.insert(id(x,y));
        vis[x][y]=1;
        if(st[x-1][y]&&!vis[x-1][y])dfs(x-1,y);
        if(st[x+1][y]&&!vis[x+1][y])dfs(x+1,y);
        if(st[x][y-1]&&!vis[x][y-1])dfs(x,y-1);
        if(st[x][y+1]&&!vis[x][y+1])dfs(x,y+1);
        if(ok[x-1][y]&&!st[x-1][y])se.insert(id(x-1,y));
        if(ok[x+1][y]&&!st[x+1][y])se.insert(id(x+1,y));
        if(ok[x][y-1]&&!st[x][y-1])se.insert(id(x,y-1));
        if(ok[x][y+1]&&!st[x][y+1])se.insert(id(x,y+1));
    }
    void main(){
        cin>>n>>m;
    	rep(i,1,n)rep(j,1,m)ok[i][j]=st[i][j]=1;
        rep(i,1,n)rep(j,1,m){
            char ch;
            cin>>ch;
            if(ch=='#')ok[i][j]=st[i][j]=st[i-1][j]=st[i][j-1]=st[i+1][j]=st[i][j+1]=0;
        }
        rep(i,1,n)rep(j,1,m)if(st[i][j]&&!vis[i][j])unordered_set<int>().swap(se),dfs(i,j),ans=max(ans,sizc(se));
        cout<<ans<<'\n';
    }
}
signed main(){
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    KnownError_::main();
}

Submission Info

Submission Time
Task D - Grid and Magnet
User KnownError_
Language C++ 20 (gcc 12.2)
Score 425
Code Size 1689 Byte
Status AC
Exec Time 171 ms
Memory 204892 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 2
AC × 52
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3424 KB
example_01.txt AC 1 ms 3520 KB
hand_00.txt AC 1 ms 3388 KB
hand_01.txt AC 167 ms 204892 KB
hand_02.txt AC 10 ms 5484 KB
hand_03.txt AC 10 ms 5548 KB
hand_04.txt AC 47 ms 7168 KB
hand_05.txt AC 161 ms 178792 KB
hand_06.txt AC 158 ms 178632 KB
hand_07.txt AC 162 ms 204396 KB
hand_08.txt AC 162 ms 204280 KB
hand_09.txt AC 135 ms 126040 KB
hand_10.txt AC 136 ms 125964 KB
hand_11.txt AC 1 ms 3564 KB
hand_12.txt AC 1 ms 3492 KB
hand_13.txt AC 1 ms 3516 KB
random_00.txt AC 142 ms 111892 KB
random_01.txt AC 145 ms 106520 KB
random_02.txt AC 145 ms 109000 KB
random_03.txt AC 162 ms 56188 KB
random_04.txt AC 156 ms 58376 KB
random_05.txt AC 161 ms 58384 KB
random_06.txt AC 56 ms 6440 KB
random_07.txt AC 57 ms 6548 KB
random_08.txt AC 57 ms 6504 KB
random_09.txt AC 23 ms 6464 KB
random_10.txt AC 25 ms 6320 KB
random_11.txt AC 24 ms 6360 KB
random_12.txt AC 10 ms 5604 KB
random_13.txt AC 10 ms 5412 KB
random_14.txt AC 11 ms 5480 KB
random_15.txt AC 171 ms 201368 KB
random_16.txt AC 155 ms 172428 KB
random_17.txt AC 148 ms 108268 KB
random_18.txt AC 10 ms 5476 KB
random_19.txt AC 10 ms 5392 KB
random_20.txt AC 12 ms 5476 KB
random_21.txt AC 10 ms 5320 KB
random_22.txt AC 10 ms 5672 KB
random_23.txt AC 12 ms 6364 KB
random_24.txt AC 43 ms 6348 KB
random_25.txt AC 43 ms 6440 KB
random_26.txt AC 47 ms 6452 KB
random_27.txt AC 43 ms 6464 KB
random_28.txt AC 43 ms 6456 KB
random_29.txt AC 43 ms 6304 KB
random_30.txt AC 44 ms 6460 KB
random_31.txt AC 48 ms 6652 KB
random_32.txt AC 47 ms 6564 KB
random_33.txt AC 47 ms 6836 KB
random_34.txt AC 46 ms 7028 KB
random_35.txt AC 47 ms 6940 KB


2025-03-18 (Tue)
16:33:55 +00:00