結果

問題 No.697 池の数はいくつか
ユーザー troro_kelptroro_kelp
提出日時 2018-10-16 16:58:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 933 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 75,196 KB
実行使用メモリ 472,320 KB
最終ジャッジ日時 2024-05-04 06:16:48
合計ジャッジ時間 12,163 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 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,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 155 ms
7,424 KB
testcase_25 AC 153 ms
7,552 KB
testcase_26 AC 152 ms
7,552 KB
testcase_27 AC 159 ms
7,552 KB
testcase_28 AC 166 ms
7,552 KB
testcase_29 MLE -
testcase_30 AC 1,399 ms
50,432 KB
testcase_31 MLE -
testcase_32 AC 1,392 ms
50,432 KB
testcase_33 AC 1,411 ms
50,432 KB
testcase_34 AC 1,389 ms
50,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int H, W;
int dxy[5] = {-1, 0, 1, 0, -1};
vector<vector<int>> v(3010);
int ans;
void dfs(int y, int x)
{
    if (v[y][x] == 0)
        return;
    v[y][x] = 0;
    for (int i = 1; i < 5; ++i)
    {
        int ny = y + dxy[i], nx = x + dxy[i - 1];
        if (ny >= 0 && nx >= 0 && ny < H && nx < W && v[ny][nx] != 0)
        {
            dfs(ny, nx);
        }
    }
    return;
}
int main(void)
{
    cin >> H >> W;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            int a;
            cin >> a;
            v[i].push_back(a);
        }
    }
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            if (v[i][j])
            {
                dfs(i, j);
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0