結果

問題 No.697 池の数はいくつか
ユーザー KKT89KKT89
提出日時 2021-03-04 01:09:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 916 ms / 6,000 ms
コード長 970 bytes
コンパイル時間 2,510 ms
コンパイル使用メモリ 206,940 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 21:02:36
合計ジャッジ時間 10,232 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,948 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 102 ms
6,940 KB
testcase_25 AC 103 ms
6,940 KB
testcase_26 AC 101 ms
6,940 KB
testcase_27 AC 102 ms
6,940 KB
testcase_28 AC 103 ms
6,940 KB
testcase_29 AC 786 ms
6,940 KB
testcase_30 AC 916 ms
6,940 KB
testcase_31 AC 786 ms
6,944 KB
testcase_32 AC 904 ms
6,944 KB
testcase_33 AC 901 ms
6,940 KB
testcase_34 AC 901 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w; cin >> h >> w;
	vector<vector<bool>> f(h,vector<bool>(w,false));
	auto used=f;
	queue<int> q;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int c; cin >> c;
			f[i][j]=c;
		}
	}
	int res=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(f[i][j]){
				if(used[i][j])continue;
				res++;
				q.push(i*w+j);
				while(q.size()){
					int p=q.front(); q.pop();
					int x=p/w,y=p%w;
					for(int k=0;k<4;k++){
						int nx=x+dx[k],ny=y+dy[k];
						if(0<=nx and nx<h and 0<=ny and ny<w and f[nx][ny] and !used[nx][ny]){
							used[nx][ny]=true;
							q.push(nx*w+ny);
						}
					}
				}
			}
		}
	}
	printf("%d\n",res);
}
0