結果

問題 No.697 池の数はいくつか
ユーザー yuji9511yuji9511
提出日時 2019-07-07 10:03:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 877 ms / 6,000 ms
コード長 1,623 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 165,576 KB
実行使用メモリ 47,800 KB
最終ジャッジ日時 2024-04-25 20:30:33
合計ジャッジ時間 9,235 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 102 ms
17,880 KB
testcase_25 AC 102 ms
19,128 KB
testcase_26 AC 103 ms
17,760 KB
testcase_27 AC 103 ms
17,760 KB
testcase_28 AC 102 ms
19,156 KB
testcase_29 AC 820 ms
47,676 KB
testcase_30 AC 877 ms
47,516 KB
testcase_31 AC 821 ms
47,800 KB
testcase_32 AC 872 ms
47,560 KB
testcase_33 AC 870 ms
47,540 KB
testcase_34 AC 868 ms
47,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
bool check[3010][3010] = {};
int A[3010][3010] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    rep(i,0,H){
        rep(j,0,W){
            cin >> A[i][j];
        }
    }
    ll ans = 0;
    ll dx[4] = {0,0,1,-1};
    ll dy[4] = {1,-1,0,0};
    rep(h,0,H){
        rep(w,0,W){
            if(check[h][w] == 1 || A[h][w] == 0) continue;
            // print2(h,w);
            ans++;
            queue<lpair> q;
            q.push(make_pair(h,w));
            while(!q.empty()){
                lpair l1 = q.front();
                q.pop();
                if(check[l1.first][l1.second]) continue;
                check[l1.first][l1.second] = 1;
                rep(k,0,4){
                    ll hy = l1.first + dy[k];
                    ll wx = l1.second + dx[k];
                    
                    if(hy >= 0 && hy < H && wx >= 0 && wx < W){
                        
                        if(check[hy][wx] == 0 && A[hy][wx] == 1){
                            
                            q.push(make_pair(hy, wx));
                        }
                    }
                }

            }

        }
    }
    print(ans);
    
    
}
0