結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
glreto
|
| 提出日時 | 2020-11-01 18:49:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,686 ms / 6,000 ms |
| コード長 | 1,330 bytes |
| コンパイル時間 | 2,217 ms |
| コンパイル使用メモリ | 175,448 KB |
| 実行使用メモリ | 112,120 KB |
| 最終ジャッジ日時 | 2024-11-08 08:48:14 |
| 合計ジャッジ時間 | 14,345 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#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();
int x = p.first, y = p.second;
F[x][y] = 0;
if (x < h - 1 && F[x + 1][y] == 1) sta.push({x + 1, y});
if (y < w - 1 && F[x][y + 1] == 1) sta.push({x, y + 1});
if (x > 0 && F[x - 1][y] == 1) sta.push({x - 1, y});
if (y > 0 && F[x][y - 1] == 1) sta.push({x, y - 1});
}
ans++;
}
}
}
cout << ans << endl;
getchar(); getchar();
}
glreto