結果

問題 No.697 池の数はいくつか
ユーザー troro_kelptroro_kelp
提出日時 2018-10-16 17:01:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,007 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 69,396 KB
実行使用メモリ 434,000 KB
最終ジャッジ日時 2024-05-04 06:17:12
合計ジャッジ時間 12,015 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 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,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 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 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 155 ms
7,296 KB
testcase_25 AC 157 ms
6,968 KB
testcase_26 AC 155 ms
6,940 KB
testcase_27 AC 158 ms
6,940 KB
testcase_28 AC 158 ms
6,940 KB
testcase_29 MLE -
testcase_30 AC 1,405 ms
12,124 KB
testcase_31 MLE -
testcase_32 AC 1,371 ms
12,284 KB
testcase_33 AC 1,361 ms
12,172 KB
testcase_34 AC 1,358 ms
12,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void dfs(int, int)':
main.cpp:18:48: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations]
   18 |         int ny = y + dxy[i], nx = x + dxy[i + 1];
      |                                       ~~~~~~~~~^
main.cpp:16:23: note: within this loop
   16 |     for (int i = 0; i < 5; ++i)
      |                     ~~^~~

ソースコード

diff #

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

int H, W;
int dxy[5] = {-1, 0, 1, 0, -1};
bool v[3010][3010];
int ans;
void dfs(int y, int x)
{
    if (v[y][x] == false)
        return;
    v[y][x] = 0;
    for (int i = 0; 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] != false)
        {
            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;
            if (a == 1)
                v[i][j] = true;
            else
                v[i][j] = false;
        }
    }
    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