結果

問題 No.697 池の数はいくつか
ユーザー peroonperoon
提出日時 2019-06-21 07:27:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 731 ms / 6,000 ms
コード長 1,802 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 169,736 KB
実行使用メモリ 74,200 KB
最終ジャッジ日時 2024-04-25 20:30:09
合計ジャッジ時間 8,292 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 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,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 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 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 81 ms
26,872 KB
testcase_25 AC 81 ms
27,128 KB
testcase_26 AC 80 ms
28,112 KB
testcase_27 AC 79 ms
26,456 KB
testcase_28 AC 83 ms
27,188 KB
testcase_29 AC 731 ms
74,144 KB
testcase_30 AC 722 ms
74,192 KB
testcase_31 AC 723 ms
74,200 KB
testcase_32 AC 716 ms
74,008 KB
testcase_33 AC 722 ms
73,924 KB
testcase_34 AC 720 ms
74,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

struct Point{
    ll x;
    ll y;
    Point(ll x, ll y): x(x), y(y) {}
    Point(){}
};

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

ll A[3010][3010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll H, W; cin >> H >> W;

    FOR(i, 0, H){
        FOR(j, 0, W){
            cin >> A[i][j];
        }
    }

    queue<Point> que;
    ll count = 0;
    FOR(y, 0, H){
        FOR(x, 0, W){
            if(A[y][x]==1){
                count++;
                que.push(Point(x, y));
                A[y][x] = 0;
                while(!que.empty()){
                    auto po = que.front();
                    que.pop();

                    FOR(i, 0, 4){
                        ll tx = po.x + dx[i];
                        ll ty = po.y + dy[i];
                        if(0<=tx && tx<W && 0<=ty && ty<H && A[ty][tx]==1){
                            A[ty][tx]=0;
                            que.push(Point(tx, ty));
                        }
                    }
                }
            }
        }
    }
    p(count);
    
    return 0;
}
0