結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             wk1080id
                         | 
                    
| 提出日時 | 2019-04-24 01:14:40 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,841 bytes | 
| コンパイル時間 | 994 ms | 
| コンパイル使用メモリ | 94,352 KB | 
| 実行使用メモリ | 406,832 KB | 
| 最終ジャッジ日時 | 2024-11-25 14:46:34 | 
| 合計ジャッジ時間 | 16,410 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 MLE * 2 | 
ソースコード
#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};
signed main(void) {
    int h,w;
    cin >> h >> w;
    vector<vi> a(h,vi(w)),used(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]){
        vp v;
        queue<pii> q;
        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++;
    }
    cout << ans << endl;
}
            
            
            
        
            
wk1080id