結果

問題 No.697 池の数はいくつか
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-26 19:35:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,649 ms / 6,000 ms
コード長 1,331 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 173,908 KB
実行使用メモリ 112,152 KB
最終ジャッジ日時 2024-04-25 20:32:44
合計ジャッジ時間 14,209 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 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,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 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,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 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,940 KB
testcase_24 AC 175 ms
7,424 KB
testcase_25 AC 173 ms
7,424 KB
testcase_26 AC 173 ms
7,552 KB
testcase_27 AC 172 ms
7,552 KB
testcase_28 AC 172 ms
7,552 KB
testcase_29 AC 1,649 ms
112,152 KB
testcase_30 AC 1,549 ms
38,656 KB
testcase_31 AC 1,644 ms
112,112 KB
testcase_32 AC 1,564 ms
38,528 KB
testcase_33 AC 1,553 ms
38,656 KB
testcase_34 AC 1,557 ms
38,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

int main() {
    int h, w; cin >> h >> w;
    vector<vector<int>> F(h, vector<int>(w));
    REP(i, h) {
        REP(j, w) {
            cin >> F[i][j];
        }
    }
    int ans = 0;
    REP(i, h) {
        REP(j, w) {
            if (F[i][j] == 1) {
                stack<pair<int, int>> sta;
                sta.push({i,j});
                while (!sta.empty()) {
                    pair<int, int> p = sta.top(); sta.pop();
                    int x = p.first, y = p.second;
                    F[x][y] = 0;
                    if (x < h - 1 && F[x + 1][y] == 1) sta.push({x + 1, y});
                    if (y < w - 1 && F[x][y + 1] == 1) sta.push({x, y + 1});
                    if (x > 0 && F[x - 1][y] == 1) sta.push({x - 1, y});
                    if (y > 0 && F[x][y - 1] == 1) sta.push({x, y - 1});
                }
                ans++;
            }
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}
0