結果

問題 No.697 池の数はいくつか
ユーザー wk1080idwk1080id
提出日時 2019-04-24 01:18:06
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,860 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 96,904 KB
実行使用メモリ 406,980 KB
最終ジャッジ日時 2023-08-16 23:04:27
合計ジャッジ時間 15,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 187 ms
19,008 KB
testcase_25 AC 188 ms
18,840 KB
testcase_26 AC 186 ms
18,892 KB
testcase_27 AC 188 ms
18,892 KB
testcase_28 AC 187 ms
18,828 KB
testcase_29 MLE -
testcase_30 AC 1,676 ms
144,064 KB
testcase_31 MLE -
testcase_32 AC 1,675 ms
144,052 KB
testcase_33 AC 1,673 ms
144,104 KB
testcase_34 AC 1,675 ms
144,084 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};

vp v;
vector<vi> a,used;
queue<pii> q;

signed main(void) {
    int h,w;
    cin >> h >> w;
    a = used = 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));
        used[i][j]++;
        while(q.size()){
            int x = q.front().first;
            int y = q.front().second;
            v.push_back(pii(x,y));
            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] == 0 || used[nx][ny])continue;
                used[nx][ny]++;
                q.push(pii(nx,ny));
            }
        }
        rep(k,v.size()){
            a[v[k].first][v[k].second]--;
            used[v[k].first][v[k].second]--;
        }
        ans++;
        v.clear();
    }
    cout << ans << endl;
}
0