結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2019-08-26 19:30:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,293 bytes |
コンパイル時間 | 1,558 ms |
コンパイル使用メモリ | 177,372 KB |
実行使用メモリ | 38,656 KB |
最終ジャッジ日時 | 2024-11-25 15:11:00 |
合計ジャッジ時間 | 13,238 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 6 WA * 26 |
ソースコード
#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; int main() { int h, w; cin >> h >> w; vector<vector<int>> F(h, vector<int>(w)); REP(i, h) { REP(j, w) { cin >> F[i][j]; } } int ans = 0; REP(i, h) { REP(j, w) { if (F[i][j] == 1) { stack<pair<int, int>> sta; sta.push({i,j}); while (!sta.empty()) { pair<int, int> p = sta.top(); sta.pop(); F[p.first][p.second] = 0; if (i < h - 1 && F[i + 1][j] == 1) sta.push({i + 1, j}); if (j < w - 1 && F[i][j + 1] == 1) sta.push({i, j + 1}); if (i > 0 && F[i - 1][j] == 1) sta.push({i - 1, j}); if (j > 0 && F[i][j - 1] == 1) sta.push({i, j - 1}); } ans++; } } } cout << ans << endl; getchar(); getchar(); }