結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
tokizo
|
| 提出日時 | 2019-02-01 16:43:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 880 ms / 6,000 ms |
| コード長 | 1,238 bytes |
| コンパイル時間 | 1,694 ms |
| コンパイル使用メモリ | 171,832 KB |
| 実行使用メモリ | 47,744 KB |
| 最終ジャッジ日時 | 2024-11-08 08:10:42 |
| 合計ジャッジ時間 | 9,316 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int h, w;
const int MAX = 3010;
int A[MAX][MAX];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
bool seen[MAX][MAX];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> w;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
cin >> A[i][j];
}
}
int ans = 0;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(A[i][j] == 1 and !seen[i][j]){
ans++;
queue<pair<int, int>> q;
seen[i][j] = true;
q.push({i, j});
while(!q.empty()){
pair<int, int> p = q.front();
q.pop();
for(int k = 0; k < 4; k++){
int nx = dx[k] + p.first;
int ny = dy[k] + p.second;
if(nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
if(seen[nx][ny] or A[nx][ny] == 0) continue;
seen[nx][ny] = true;
q.push({nx, ny});
}
}
}
}
}
cout << ans << endl;
return 0;
}
tokizo