結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
|
| 提出日時 | 2025-01-06 23:22:10 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,532 bytes |
| コンパイル時間 | 1,201 ms |
| コンパイル使用メモリ | 108,516 KB |
| 実行使用メモリ | 713,252 KB |
| 最終ジャッジ日時 | 2025-01-06 23:22:59 |
| 合計ジャッジ時間 | 49,415 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 MLE * 2 |
| other | AC * 22 TLE * 5 MLE * 5 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
vector<vector<string>> grid(h);
for (int i = 0; i < h; ++i) {
grid[i].resize(w);
for (int j = 0; j < w; ++j) {
cin >> grid[i][j];
}
}
set<pair<int, int>> sensor;
for (int j = 0; j < h; ++j) {
for (int i = 0; i < w; ++i) {
if (grid[j][i] == "1") {
sensor.insert({i, j});
}
}
}
int count = 0;
set<pair<int, int>> visited;
while (!sensor.empty()) {
queue<pair<int, int>> q;
q.push(*sensor.begin());
sensor.erase(sensor.begin());
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
if (sensor.count({x,y})){
sensor.erase({x,y});
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
if (grid[ny][nx] == "0") continue;
if(visited.count({nx, ny}) == 0 && grid[ny][nx] == "1"){
visited.insert({nx, ny});
q.push({nx, ny});
}
}
}
count++;
}
cout << count << endl;
return 0;
}