結果

問題 No.697 池の数はいくつか
ユーザー glretoglreto
提出日時 2020-11-01 18:41:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,068 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 172,952 KB
実行使用メモリ 426,752 KB
最終ジャッジ日時 2024-04-25 20:55:16
合計ジャッジ時間 14,058 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 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,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 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 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 157 ms
6,940 KB
testcase_25 AC 157 ms
6,944 KB
testcase_26 AC 158 ms
6,944 KB
testcase_27 AC 162 ms
6,940 KB
testcase_28 AC 162 ms
6,940 KB
testcase_29 MLE -
testcase_30 AC 1,470 ms
6,944 KB
testcase_31 MLE -
testcase_32 AC 1,412 ms
6,944 KB
testcase_33 AC 1,410 ms
6,940 KB
testcase_34 AC 1,439 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const int MAX = 510000;
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
vector<vector<bool>> mp;int sum = 0,w,h;
int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
void dfs(int i,int j){
    if(mp[i][j]==0)return;
    mp[i][j] = 0;
    rep(k,4){
        if(i+dy[k]<0||i+dy[k]>=h||j+dx[k]<0||j+dx[k]>=w)continue;
        dfs(i+dy[k],j+dx[k]);
    }
}
int main(void) {
    cin >>h>>w;int a;
    mp.resize(h,vector<bool>(w));
    rep(i,h) rep(j,w) cin >> a,mp[i][j] = (a==1);
    rep(i,h) rep(j,w){
        if(mp[i][j]){
            sum++;dfs(i,j);
        }
    }cout << sum <<endl;
}
0