結果

問題 No.697 池の数はいくつか
ユーザー lunnearlunnear
提出日時 2018-11-22 15:09:41
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,025 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 56,076 KB
実行使用メモリ 574,564 KB
最終ジャッジ日時 2024-05-04 06:18:56
合計ジャッジ時間 12,044 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 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,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 164 ms
6,940 KB
testcase_25 AC 157 ms
6,940 KB
testcase_26 AC 155 ms
6,940 KB
testcase_27 AC 157 ms
6,944 KB
testcase_28 AC 156 ms
6,940 KB
testcase_29 MLE -
testcase_30 AC 1,395 ms
11,828 KB
testcase_31 MLE -
testcase_32 AC 1,402 ms
11,928 KB
testcase_33 AC 1,406 ms
11,888 KB
testcase_34 AC 1,387 ms
11,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

enum State
{
    None = -1,
    Field,
    Lake,
    Lake_Check,
};

bool ChechLake(int x, int y, char *s, const int *h, const int *w)
{
    if(s[x + y * (*w)] != (char)State::Lake)
        return false;
    
    s[x + y * (*w)] = (char)State::Lake_Check;
    
    
    if(x < ((*w) - 1))
        ChechLake(x + 1, y, s, h, w);
    
    if(x > 0)
        ChechLake(x - 1, y, s, h, w);
    
    if(y < ((*h) - 1))
        ChechLake(x, y + 1, s, h, w);
    
    if(y > 0)
        ChechLake(x, y - 1, s, h, w);
    
    return true;
}


int main()
{
    int h, w;
    std::cin >> h >> w;
    
    char *s = new char[h * w];
    for(int i = 0; i < (h * w); i++)
    {
        int a;
        std::cin >> a;
        s[i] = (char)a;
    }
    
    int count = 0;
    for(int y = 0; y < h; y++)
    {
        for(int x = 0; x < w; x++)
        {
            if(ChechLake(x, y, s, &h, &w))
                count++;
        }
    }
    
    std::cout << count << std::endl;
    
    delete[] s;
    
    return 0;
}
0