結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
|
| 提出日時 | 2023-03-31 14:25:35 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,647 bytes |
| 記録 | |
| コンパイル時間 | 1,267 ms |
| コンパイル使用メモリ | 103,712 KB |
| 実行使用メモリ | 1,308,376 KB |
| 最終ジャッジ日時 | 2026-06-30 02:48:17 |
| 合計ジャッジ時間 | 9,260 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 MLE * 2 |
| other | -- * 32 |
ソースコード
#include<iostream>
#include<vector>
#include<stack>
int main() {
int H, W;
std::cin >> H >> W;
std::vector<std::vector<bool>> A(H, std::vector<bool>(W));
for (int h = 0; h < H; ++h) {
for (int w = 0; w < W; ++w) {
int a;
std::cin >> a;
A.at(h).at(w) = bool(a);
}
}
const std::vector<std::pair<int, int>> dhw = {{0, 1},
{1, 0},
{0, -1},
{-1, 0}};
std::vector<std::vector<bool>> nonvisited(H, std::vector<bool>(W, true));
int ans = 0;
for (int h0 = 0; h0 < H; ++h0) {
for (int w0 = 0; w0 < W; ++w0) {
if (A.at(h0).at(w0) && nonvisited.at(h0).at(w0)) {
ans++;
std::stack<std::pair<int, int>> stk;
stk.emplace(h0, w0);
while (!stk.empty()) {
const auto [h, w] = stk.top();
stk.pop();
for (const auto &[dh, dw]: dhw) {
const int hdh = h + dh;
const int wdw = w + dw;
if (0 <= hdh
&& hdh < H
&& 0 <= wdw
&& wdw < W
&& A.at(hdh).at(wdw)
&& nonvisited.at(hdh).at(wdw)) {
stk.emplace(hdh, wdw);
}
}
}
}
}
}
std::cout << ans << std::endl;
}