結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-03 15:16:44 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,165 ms / 6,000 ms |
| コード長 | 1,073 bytes |
| 記録 | |
| コンパイル時間 | 2,878 ms |
| コンパイル使用メモリ | 204,284 KB |
| 最終ジャッジ日時 | 2025-01-09 12:41:11 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint h,w;std::cin>>h>>w;
std::vector<std::vector<lint>>a(h+2,std::vector<lint>(w+2,1));
for(lint i=1;i<=h;i++){
for(lint j=1;j<=w;j++){
lint x;std::cin>>x;
a.at(i).at(j)=!x;
}}
lint ans=0;
std::queue<std::pair<lint,lint>>que;
std::vector<lint>di={+1,-1,0,0};
std::vector<lint>dj={0,0,+1,-1};
for(lint si=1;si<=h;si++){
for(lint sj=1;sj<=w;sj++){
if(std::exchange(a.at(si).at(sj),true))continue;
que.emplace(si,sj);
ans++;
while(!que.empty()){
lint i,j;std::tie(i,j)=que.front();que.pop();
for(lint k=0;k<4;k++){
lint ni=i+di.at(k);
lint nj=j+dj.at(k);
if(std::exchange(a.at(ni).at(nj),true))continue;
que.emplace(ni,nj);
}
}
}}
std::cout<<ans<<'\n';
}
ngtkana