結果

問題 No.697 池の数はいくつか
ユーザー siro53siro53
提出日時 2018-12-26 14:59:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,317 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 91,700 KB
実行使用メモリ 636,492 KB
最終ジャッジ日時 2024-05-04 06:19:27
合計ジャッジ時間 12,312 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 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 1 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 173 ms
25,808 KB
testcase_25 AC 159 ms
23,756 KB
testcase_26 AC 159 ms
23,756 KB
testcase_27 AC 159 ms
25,804 KB
testcase_28 AC 157 ms
25,804 KB
testcase_29 MLE -
testcase_30 AC 1,393 ms
73,928 KB
testcase_31 MLE -
testcase_32 AC 1,390 ms
73,932 KB
testcase_33 AC 1,381 ms
73,936 KB
testcase_34 AC 1,411 ms
73,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

//入力
int h, w;
int a[3000][3001];
int reached[3000][3001];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int y, int x)
{
    a[y][x] = 0;
    reached[y][x] = 1;
    for (int i = 0; i < 4; i++)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && a[ny][nx] == 1 && reached[ny][nx] == 0)
            dfs(ny, nx);
    }
    return;
}

void solve()
{
    int ans = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] == 1)
            {
                dfs(i, j);
                ans++;
            }
        }
    }
    printf("%d\n", ans);
}

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
    }
    solve();
}
0