結果

問題 No.697 池の数はいくつか
ユーザー ngtkanangtkana
提出日時 2020-04-03 15:16:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 936 ms / 6,000 ms
コード長 1,073 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 206,480 KB
実行使用メモリ 74,240 KB
最終ジャッジ日時 2024-04-25 20:45:28
合計ジャッジ時間 10,288 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 98 ms
11,136 KB
testcase_25 AC 96 ms
11,264 KB
testcase_26 AC 96 ms
11,136 KB
testcase_27 AC 97 ms
11,136 KB
testcase_28 AC 97 ms
11,264 KB
testcase_29 AC 926 ms
74,112 KB
testcase_30 AC 877 ms
73,856 KB
testcase_31 AC 936 ms
74,240 KB
testcase_32 AC 879 ms
73,728 KB
testcase_33 AC 879 ms
73,856 KB
testcase_34 AC 877 ms
73,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0