結果

問題 No.697 池の数はいくつか
ユーザー jjjjjjjtgpptmjjjjjjjjjtgpptmjj
提出日時 2019-05-06 21:11:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,497 ms / 6,000 ms
コード長 1,145 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 165,212 KB
実行使用メモリ 38,704 KB
最終ジャッジ日時 2024-04-25 20:27:51
合計ジャッジ時間 12,894 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,948 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 166 ms
16,364 KB
testcase_25 AC 167 ms
16,632 KB
testcase_26 AC 171 ms
15,912 KB
testcase_27 AC 170 ms
15,924 KB
testcase_28 AC 171 ms
16,140 KB
testcase_29 AC 1,454 ms
38,544 KB
testcase_30 AC 1,497 ms
38,672 KB
testcase_31 AC 1,428 ms
38,696 KB
testcase_32 AC 1,485 ms
38,700 KB
testcase_33 AC 1,490 ms
38,704 KB
testcase_34 AC 1,475 ms
38,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define push_back pb
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int H,W;
int A[3005][3005];
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,1,-1};
bool in(int x, int y){
	return 0<=x&&x<H&&0<=y&&y<W;
}

void bfs(int a,int b){
	queue<P> Q;
	Q.push({a,b});
	while(!Q.empty()){
		P p = Q.front();
		Q.pop();
		int x = p.first, y = p.second;
		rep(i,4){
			int nx = x + dx[i], ny = y + dy[i];
			if(!in(nx,ny)||A[nx][ny] == 0)continue;
			A[nx][ny] = 0;
			Q.push({nx,ny});
		}
	}
}
int main() {
	cin>>H>>W;
	rep(i,H)rep(j,W){
		cin>>A[i][j];
	}
/*	rep(i,H){
		rep(j,W){
			cerr<<A[i][j];
		}
		cerr<<endl;
	}*/
	int ans = 0;
	rep(i,H)rep(j,W){
		if(A[i][j] == 1){
			bfs(i,j);
			ans++;
		}
	}
	cout<<ans<<endl;
}
0