結果

問題 No.697 池の数はいくつか
ユーザー wk1080idwk1080id
提出日時 2019-04-24 01:34:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,623 ms / 6,000 ms
コード長 1,623 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 92,000 KB
実行使用メモリ 73,984 KB
最終ジャッジ日時 2024-04-25 20:26:24
合計ジャッジ時間 13,302 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 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,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,948 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 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,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 176 ms
11,008 KB
testcase_25 AC 179 ms
10,880 KB
testcase_26 AC 177 ms
11,008 KB
testcase_27 AC 172 ms
10,880 KB
testcase_28 AC 175 ms
11,136 KB
testcase_29 AC 1,623 ms
73,856 KB
testcase_30 AC 1,582 ms
73,728 KB
testcase_31 AC 1,609 ms
73,984 KB
testcase_32 AC 1,550 ms
73,728 KB
testcase_33 AC 1,544 ms
73,728 KB
testcase_34 AC 1,554 ms
73,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

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

vector<vi> a;
queue<pii> q;

signed main(void) {
    int h,w;
    cin >> h >> w;
    a = vector<vi> (h,vi(w));
    rep(i,h)rep(j,w)cin >> a[i][j];
    int ans = 0;
    rep(i,h)rep(j,w)if(a[i][j]){
        q.push(pii(i,j));
        while(q.size()){
            int x = q.front().first;
            int y = q.front().second;
            q.pop();
            rep(k,4){
                int nx = x + dx[k];
                int ny = y + dy[k];
                if(nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
                if(!a[nx][ny])continue;
                a[nx][ny] = 0;
                q.push(pii(nx,ny));
            }
        }
        ans++;
    }
    cout << ans << endl;
}
0