結果

問題 No.697 池の数はいくつか
ユーザー Mcpu3Mcpu3
提出日時 2019-08-15 00:10:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,557 ms / 6,000 ms
コード長 1,631 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 85,368 KB
実行使用メモリ 39,980 KB
最終ジャッジ日時 2023-08-08 02:33:42
合計ジャッジ時間 13,268 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 172 ms
7,652 KB
testcase_25 AC 173 ms
7,524 KB
testcase_26 AC 173 ms
7,536 KB
testcase_27 AC 172 ms
7,428 KB
testcase_28 AC 171 ms
7,372 KB
testcase_29 AC 1,473 ms
39,836 KB
testcase_30 AC 1,550 ms
39,792 KB
testcase_31 AC 1,515 ms
39,840 KB
testcase_32 AC 1,551 ms
39,936 KB
testcase_33 AC 1,557 ms
39,820 KB
testcase_34 AC 1,551 ms
39,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int H, W, ans = 0;
	cin >> H >> W;
	vector<vector<int>> A(H, vector<int>(W));
	for (vector<int>& i : A) {
		for (int& j : i) cin >> j;
	}
	vector<vector<bool>> a(H, vector<bool>(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (!a[i][j] && A[i][j]) {
				++ans;
				a[i][j] = true;
				queue<pair<int, int>> b;
				b.emplace(i, j);
				while (!b.empty()) {
					if (H - 1 != b.front().first) {
						if (!a[1 + b.front().first][b.front().second] && A[1 + b.front().first][b.front().second]) {
							a[1 + b.front().first][b.front().second] = true;
							b.emplace(1 + b.front().first, b.front().second);
						}
					}
					if (W - 1 != b.front().second) {
						if (!a[b.front().first][1 + b.front().second] && A[b.front().first][1 + b.front().second]) {
							a[b.front().first][1 + b.front().second] = true;
							b.emplace(b.front().first, 1 + b.front().second);
						}
					}
					if (b.front().first) {
						if (!a[b.front().first - 1][b.front().second] && A[b.front().first - 1][b.front().second]) {
							a[b.front().first - 1][b.front().second] = true;
							b.emplace(b.front().first - 1, b.front().second);
						}
					}
					if (b.front().second) {
						if (!a[b.front().first][b.front().second - 1] && A[b.front().first][b.front().second - 1]) {
							a[b.front().first][b.front().second - 1] = true;
							b.emplace(b.front().first, b.front().second - 1);
						}
					}
					b.pop();
				}
			}
		}
	}
	cout << ans;
}
0