結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
srup٩(๑`н´๑)۶
|
| 提出日時 | 2018-06-09 23:40:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,586 ms / 6,000 ms |
| コード長 | 827 bytes |
| コンパイル時間 | 2,876 ms |
| コンパイル使用メモリ | 162,532 KB |
| 実行使用メモリ | 38,912 KB |
| 最終ジャッジ日時 | 2024-11-08 07:42:32 |
| 合計ジャッジ時間 | 14,202 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
int h, w;
int a[3010][3010];
const int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1};
int main(int argc, char const *argv[])
{
cin >> h >> w;
rep(i, h)rep(j, w) cin >> a[i][j];
int ans = 0;
rep(i, h)rep(j, w) {
if (a[i][j] == 0) continue;
queue<pair<int, int>> que;
que.push(make_pair(i, j));
a[i][j] = 0;
ans++;
while(!que.empty()) {
int y = que.front().first, x = que.front().second;
que.pop();
rep(k, 4) {
int ny = y + dy[k], nx = x + dx[k];
if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
if (a[ny][nx] == 1) {
a[ny][nx] = 0;
que.push(make_pair(ny, nx));
}
}
}
}
printf("%d\n", ans);
return 0;
}
srup٩(๑`н´๑)۶