結果

問題 No.697 池の数はいくつか
ユーザー xuzijian629xuzijian629
提出日時 2018-08-29 23:20:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,700 ms / 6,000 ms
コード長 1,222 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 107,572 KB
実行使用メモリ 293,616 KB
最終ジャッジ日時 2024-04-25 20:17:30
合計ジャッジ時間 13,572 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 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 1 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 173 ms
7,596 KB
testcase_25 AC 175 ms
7,496 KB
testcase_26 AC 172 ms
7,312 KB
testcase_27 AC 173 ms
8,408 KB
testcase_28 AC 173 ms
8,264 KB
testcase_29 AC 1,700 ms
293,616 KB
testcase_30 AC 1,546 ms
12,348 KB
testcase_31 AC 1,697 ms
293,180 KB
testcase_32 AC 1,533 ms
12,240 KB
testcase_33 AC 1,543 ms
12,432 KB
testcase_34 AC 1,526 ms
12,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 mod = 1e9 + 7;
using vi = vector<i64>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

int h, w;
bool board[3000][3000];

inline bool is_valid(const ii p) {
    return 0 <= p.first && p.first < h && 0 <= p.second && p.second < w;
}

void dfs(const ii p) {
    if (is_valid(p) && board[p.first][p.second]) {
        board[p.first][p.second] = 0;
        dfs(ii(p.first + 1, p.second));
        dfs(ii(p.first - 1, p.second));
        dfs(ii(p.first, p.second + 1));
        dfs(ii(p.first, p.second - 1));
    }
}

int cnt;

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> board[i][j];
        }
    }
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (board[i][j]) {
                dfs(ii(i, j));
                cnt++;
            }
        }
    }
    
    cout << cnt << endl;
}
0