結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
|
| 提出日時 | 2022-12-22 04:30:22 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 900 ms / 6,000 ms |
| コード長 | 1,234 bytes |
| 記録 | |
| コンパイル時間 | 2,339 ms |
| コンパイル使用メモリ | 179,736 KB |
| 実行使用メモリ | 6,016 KB |
| 最終ジャッジ日時 | 2024-11-18 03:13:51 |
| 合計ジャッジ時間 | 10,056 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int h, w, ans = 0, v;
cin >> h >> w;
vector<vector<bool>> A(h, vector<bool>(w)), B(h, vector<bool>(w));
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
cin >> v;
A[y][x] = v;
}
}
queue<pair<int,int>> nxt;
for(int cy = 0; cy < h; cy++){
for(int cx = 0; cx < w; cx++){
if(B[cy][cx])continue;
if(!A[cy][cx])continue;
ans++;
B[cy][cx] = true;
nxt.emplace(cy, cx);
while(!nxt.empty()){
int y, x;
tie(y, x) = nxt.front();
nxt.pop();
for(int i = 0; i < 4; i++){
int ny = y + (i == 0) - (i == 1);
int nx = x + (i == 2) - (i == 3);
if(ny < 0 || nx < 0 || ny >= h || nx >= w)continue;
if(B[ny][nx])continue;
if(A[ny][nx] ^ A[y][x])continue;
B[ny][nx] = true;
nxt.emplace(ny, nx);
}
}
}
}
cout << ans << '\n';
}