結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
|
| 提出日時 | 2019-09-14 23:05:29 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,740 ms / 6,000 ms |
| コード長 | 803 bytes |
| 記録 | |
| コンパイル時間 | 2,016 ms |
| コンパイル使用メモリ | 171,532 KB |
| 実行使用メモリ | 38,656 KB |
| 最終ジャッジ日時 | 2024-11-08 08:22:20 |
| 合計ジャッジ時間 | 14,842 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int h, w;
int a[3000][3000];
void bfs(int sy, int sx) {
queue<pair<int, int> > que;
que.push(make_pair(sy, sx));
while (!que.empty()) {
int y = que.front().first;
int x = que.front().second;
que.pop();
if (a[y][x] == 0) {
continue;
}
a[y][x] = 0;
if (y > 0) que.push(make_pair(y-1, x));
if (y < h-1) que.push(make_pair(y+1, x));
if (x > 0) que.push(make_pair(y, x-1));
if (x < w-1) que.push(make_pair(y, x+1));
}
}
int main() {
cin>>h>>w;
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
cin>>a[i][j];
}
}
int cnt = 0;
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
if (a[i][j] == 1) {
++cnt;
bfs(i, j);
}
}
}
cout<<cnt<<endl;
}