結果

問題 No.697 池の数はいくつか
ユーザー prtoq3prtoq3
提出日時 2018-10-21 18:27:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,632 ms / 6,000 ms
コード長 955 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 164,600 KB
実行使用メモリ 112,116 KB
最終ジャッジ日時 2024-04-25 20:21:04
合計ジャッジ時間 13,698 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 170 ms
14,852 KB
testcase_25 AC 168 ms
14,996 KB
testcase_26 AC 166 ms
15,048 KB
testcase_27 AC 168 ms
14,808 KB
testcase_28 AC 171 ms
14,756 KB
testcase_29 AC 1,609 ms
112,076 KB
testcase_30 AC 1,500 ms
38,760 KB
testcase_31 AC 1,632 ms
112,116 KB
testcase_32 AC 1,505 ms
38,596 KB
testcase_33 AC 1,527 ms
38,568 KB
testcase_34 AC 1,543 ms
38,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX_N = 3010;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)

int field[MAX_N][MAX_N];
int h, w;
typedef pair<int, int> P;

void dfs(int x, int y){
    stack<P> s;
    s.push(P(x, y));

    while(s.size()){
        P p = s.top(); s.pop();
        field[p.first][p.second] = 0;

        for (int i = 0; i < 4; i++){
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny]){
                s.push(P(nx, ny));
            }
        }
    }
}

int main(){
    cin >> h >> w;
    int i, j;
    REP(i, h) REP(j, w) cin >> field[i][j];
    
    int ans = 0;
    REP(i, h) REP(j, w){
        if (field[i][j]){
            dfs(i, j);
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}
0