結果

問題 No.697 池の数はいくつか
ユーザー gazellegazelle
提出日時 2018-06-09 17:46:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 717 ms / 6,000 ms
コード長 1,454 bytes
コンパイル時間 1,257 ms
コンパイル使用メモリ 127,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 01:53:52
合計ジャッジ時間 8,181 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 82 ms
4,380 KB
testcase_25 AC 82 ms
4,376 KB
testcase_26 AC 82 ms
4,376 KB
testcase_27 AC 83 ms
4,376 KB
testcase_28 AC 84 ms
4,376 KB
testcase_29 AC 663 ms
4,376 KB
testcase_30 AC 717 ms
4,380 KB
testcase_31 AC 665 ms
4,376 KB
testcase_32 AC 717 ms
4,380 KB
testcase_33 AC 714 ms
4,376 KB
testcase_34 AC 717 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-7
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

ll h,w;
vector<bitset<3000>> a(3000);

void bfs(P pos) {
	a[pos.first][pos.second]=0;
	queue<P> q;
	q.push(pos);
	while(!q.empty()) {
		P p=q.front();
		q.pop();
		ll dx[]={1,0,-1,0};
		ll dy[]={0,1,0,-1};
		REP(i,4) {
			ll nx=p.first+dx[i];
			ll ny=p.second+dy[i];
			if(nx>=0&&nx<h&&ny>=0&&ny<w&&a[nx][ny]==1) {
				a[nx][ny]=0;
				q.push(P(nx,ny));
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>h>>w;
	REP(i,h) REP(j,w) {
		ll hoge;
		cin>>hoge;
		a[i][j]=hoge;
	}/*
	if(h==3000&&w==3000) {
		cout<<9000000<<endl;
		return 0;
	}
	  */
	ll sum=0;
	REP(i,h) REP(j,w) {
		if(a[i][j]) {
			sum++;
			bfs(P(i,j));
		}
	}
	cout<<sum<<endl;
}
0