結果

問題 No.697 池の数はいくつか
ユーザー matsukin1111matsukin1111
提出日時 2019-04-30 11:03:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,406 bytes
コンパイル時間 976 ms
コンパイル使用メモリ 97,604 KB
実行使用メモリ 610,496 KB
最終ジャッジ日時 2023-08-16 23:03:59
合計ジャッジ時間 9,627 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
12,456 KB
testcase_01 AC 8 ms
12,444 KB
testcase_02 AC 8 ms
12,460 KB
testcase_03 AC 9 ms
12,444 KB
testcase_04 AC 9 ms
12,396 KB
testcase_05 AC 8 ms
12,372 KB
testcase_06 AC 9 ms
12,472 KB
testcase_07 AC 8 ms
12,388 KB
testcase_08 AC 9 ms
12,584 KB
testcase_09 AC 8 ms
12,456 KB
testcase_10 AC 8 ms
12,480 KB
testcase_11 AC 8 ms
12,468 KB
testcase_12 AC 9 ms
12,440 KB
testcase_13 AC 8 ms
12,548 KB
testcase_14 AC 8 ms
12,468 KB
testcase_15 AC 9 ms
12,396 KB
testcase_16 AC 9 ms
12,544 KB
testcase_17 AC 8 ms
12,516 KB
testcase_18 AC 9 ms
12,380 KB
testcase_19 AC 9 ms
12,512 KB
testcase_20 AC 8 ms
12,468 KB
testcase_21 AC 9 ms
12,456 KB
testcase_22 AC 8 ms
12,588 KB
testcase_23 AC 9 ms
12,480 KB
testcase_24 AC 101 ms
20,264 KB
testcase_25 AC 101 ms
20,288 KB
testcase_26 AC 100 ms
20,284 KB
testcase_27 AC 101 ms
20,396 KB
testcase_28 AC 101 ms
20,396 KB
testcase_29 MLE -
testcase_30 AC 801 ms
47,956 KB
testcase_31 MLE -
testcase_32 AC 802 ms
47,956 KB
testcase_33 AC 799 ms
47,896 KB
testcase_34 AC 799 ms
47,952 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 dfs(int x,int y) {
	if (used[y][x] != 0)return;

	used[y][x] = 1;
	int dx[4] = {-1,0,1,0};
	int dy[4] = { 0,-1,0,1 };
	rep(i, 0, 4) {
		int _x = x + dx[i];
		int _y = y + dy[i];
		if (0 <= _x && _x <= w - 1 && 0 <= _y && _y <= h - 1) {
			if (used[_y][_x] == 0 && mp[_y][_x] == '1') {
				dfs(_x, _y);
			}
		}
	}
	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) {
			dfs(j,i);
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}
0