結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-07-06 20:26:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 980 ms / 6,000 ms |
コード長 | 1,100 bytes |
コンパイル時間 | 2,866 ms |
コンパイル使用メモリ | 205,880 KB |
最終ジャッジ日時 | 2025-01-06 11:50:16 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const int INF = (1 << 30) - 1; const ll INF64 = ((ll)1 << 62) - 1; const double PI = 3.1415926535897932384626433832795; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; int h, w; vector<vector<int>> a; void bfs(int sy, int sx) { queue<pair<int, int>> que; que.emplace(sy, sx); a[sy][sx] = 0; while (!que.empty()) { pair<int, int> now = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int ny = now.first + dy[i]; int nx = now.second + dx[i]; if (nx < 0 || w <= nx || ny < 0 || h <= ny || a[ny][nx] == 0) { continue; } a[ny][nx] = 0; que.emplace(ny, nx); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> h >> w; a.resize(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] != 1) { continue; } bfs(i, j); ans++; } } cout << ans << endl; return 0; }