結果

問題 No.697 池の数はいくつか
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-12 17:54:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 989 ms / 6,000 ms
コード長 1,198 bytes
コンパイル時間 1,072 ms
コンパイル使用メモリ 78,196 KB
実行使用メモリ 39,320 KB
最終ジャッジ日時 2024-04-25 20:59:16
合計ジャッジ時間 9,491 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 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,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 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 2 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,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 113 ms
16,312 KB
testcase_25 AC 112 ms
16,416 KB
testcase_26 AC 114 ms
16,640 KB
testcase_27 AC 113 ms
16,288 KB
testcase_28 AC 111 ms
15,192 KB
testcase_29 AC 956 ms
39,248 KB
testcase_30 AC 989 ms
39,132 KB
testcase_31 AC 936 ms
39,248 KB
testcase_32 AC 981 ms
39,212 KB
testcase_33 AC 982 ms
39,320 KB
testcase_34 AC 980 ms
39,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

//frog
int A[3030][3030];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

int main()
{
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            scanf("%d", &A[i][j]);
        }
    }

    int ans = 0, nx, ny;
    queue<pair<int, int>> que;
    pair<int, int> P;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (A[i][j] == 1) {
                ans++;
                A[i][j] = 0;
                que.push(make_pair(i, j));
                while (!que.empty()) {
                    P = que.front(); que.pop();
                    for (int k = 0; k < 4; k++){
                        nx = P.first + dx[k];
                        ny = P.second + dy[k];
                        if (0 <= nx && nx < h && 0 <= ny && ny < w && A[nx][ny] == 1) {
                            A[nx][ny] = 0;
                            que.push(make_pair(nx, ny));
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0