結果

問題 No.697 池の数はいくつか
ユーザー matsukin1111matsukin1111
提出日時 2019-04-30 11:11:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 883 ms / 6,000 ms
コード長 1,576 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 100,944 KB
実行使用メモリ 47,992 KB
最終ジャッジ日時 2023-08-08 02:27:08
合計ジャッジ時間 9,070 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
12,420 KB
testcase_01 AC 8 ms
12,552 KB
testcase_02 AC 8 ms
12,312 KB
testcase_03 AC 8 ms
12,428 KB
testcase_04 AC 8 ms
12,372 KB
testcase_05 AC 8 ms
12,360 KB
testcase_06 AC 8 ms
12,616 KB
testcase_07 AC 8 ms
12,376 KB
testcase_08 AC 8 ms
12,308 KB
testcase_09 AC 8 ms
12,420 KB
testcase_10 AC 8 ms
12,368 KB
testcase_11 AC 8 ms
12,696 KB
testcase_12 AC 8 ms
12,488 KB
testcase_13 AC 8 ms
12,352 KB
testcase_14 AC 8 ms
12,552 KB
testcase_15 AC 8 ms
12,388 KB
testcase_16 AC 8 ms
12,500 KB
testcase_17 AC 8 ms
12,340 KB
testcase_18 AC 9 ms
12,552 KB
testcase_19 AC 8 ms
12,552 KB
testcase_20 AC 9 ms
12,352 KB
testcase_21 AC 8 ms
12,384 KB
testcase_22 AC 8 ms
12,472 KB
testcase_23 AC 9 ms
12,340 KB
testcase_24 AC 108 ms
20,236 KB
testcase_25 AC 108 ms
20,532 KB
testcase_26 AC 109 ms
20,208 KB
testcase_27 AC 109 ms
20,288 KB
testcase_28 AC 108 ms
20,440 KB
testcase_29 AC 835 ms
47,848 KB
testcase_30 AC 874 ms
47,992 KB
testcase_31 AC 838 ms
47,876 KB
testcase_32 AC 883 ms
47,876 KB
testcase_33 AC 873 ms
47,828 KB
testcase_34 AC 876 ms
47,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

vector<vector<char>>mp(3030,vector<char>(3030));
int used[3030][3030];
int h, w;

void bfs(int x, int y) {

	used[y][x] = 1;
	queue<pair<int, int>>q;
	q.push({x,y});

	while (!q.empty()) {
		auto now = q.front();
		q.pop();
		int xnow = now.first;
		int ynow = now.second;

		int dx[4] = { -1,0,1,0 };
		int dy[4] = { 0,-1,0,1 };
		rep(i, 0, 4) {
			int _x = xnow + dx[i];
			int _y = ynow + dy[i];
			if (0 <= _x && _x <= w - 1 && 0 <= _y && _y <= h - 1) {
				if (used[_y][_x] == 0 && mp[_y][_x] == '1') {
					q.push({ _x,_y });
					used[_y][_x] = 1;
				}
			}
		}
	}
	return;
}

int main() {
	cin >> h >> w;

	rep(i, 0, h)rep(j,0,w)cin >> mp[i][j];

	int ans = 0;
	rep(i, 0, h)rep(j,0,w){
		if (mp[i][j] == '1' && used[i][j] == 0) {
			bfs(j,i);
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}
0