結果

問題 No.697 池の数はいくつか
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-26 19:30:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,293 bytes
コンパイル時間 3,222 ms
コンパイル使用メモリ 174,288 KB
実行使用メモリ 38,700 KB
最終ジャッジ日時 2023-08-16 23:15:56
合計ジャッジ時間 13,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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();
                    F[p.first][p.second] = 0;
                    if (i < h - 1 && F[i + 1][j] == 1) sta.push({i + 1, j});
                    if (j < w - 1 && F[i][j + 1] == 1) sta.push({i, j + 1});
                    if (i > 0 && F[i - 1][j] == 1) sta.push({i - 1, j});
                    if (j > 0 && F[i][j - 1] == 1) sta.push({i, j - 1});
                }
                ans++;
            }
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}
0