結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 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 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 158 ms
23,752 KB
testcase_25 AC 157 ms
23,884 KB
testcase_26 AC 158 ms
25,804 KB
testcase_27 AC 160 ms
23,884 KB
testcase_28 AC 158 ms
25,804 KB
testcase_29 MLE -
testcase_30 AC 1,436 ms
73,936 KB
testcase_31 MLE -
testcase_32 AC 1,395 ms
73,932 KB
testcase_33 AC 1,384 ms
73,936 KB
testcase_34 AC 1,376 ms
74,060 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]))
            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