結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2020-09-02 15:17:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 975 ms / 6,000 ms |
コード長 | 1,150 bytes |
コンパイル時間 | 2,336 ms |
コンパイル使用メモリ | 198,660 KB |
最終ジャッジ日時 | 2025-01-14 03:33:34 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); int h, w; int bd[3000][3000]; int dy[] = {0, 1, 0, -1}; int dx[] = {1, 0, -1, 0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> bd[i][j]; int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (bd[i][j]) { ++cnt; queue<pair<int, int> > q; q.emplace(i, j); bd[i][j] = 0; while (!q.empty()) { int y, x; tie(y, x) = q.front(); q.pop(); for (int k = 0; k < 4; k++) { int yt = y + dy[k]; int xt = x + dx[k]; if (yt < 0 || yt >= h) continue; if (xt < 0 || xt >= w) continue; if (bd[yt][xt]) { bd[yt][xt] = 0; q.emplace(yt, xt); } } } } } } cout << cnt << endl; return 0; }