結果

問題 No.697 池の数はいくつか
ユーザー IL_mstaIL_msta
提出日時 2018-06-12 20:04:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,386 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 124,608 KB
実行使用メモリ 11,772 KB
最終ジャッジ日時 2023-08-16 22:28:41
合計ジャッジ時間 10,764 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

int R,C;
vector<vector<int> > fld;
int index(int r,int c){
	return r*C+c;
}

int dr[] = {0,1,0,-1};
int dc[] = {1,0,-1,0};

void cal(int r,int c,int color){
	vector<vector<bool> > visit(R,vector<bool>(C,false) );
	vector<int> start(2);
	start[0] = r;
	start[1] = c;
	queue< vector<int> > now,next,zero;

	//visit[index(start[0],start[1]) ] = true;
	visit[start[0]][start[1]] = true;
	fld[start[0]][start[1]] = color;

	next.push( start );
	
	vector<int> temp(2);

	while(next.size()){
		now = next;
		next = zero;
		while(now.size()){
			vector<int> dat = now.front();
			now.pop();
			for(int k=0;k<4;++k){
				int rr = dat[0] + dr[k];
				int cc = dat[1] + dc[k];
				if(rr<0 || R<= rr || cc<0 || C<= cc){
					continue;//範囲外
				}
				if(fld[rr][cc] == 0){//水じゃない
					continue;
				}
				if(fld[rr][cc]==-1){//隣接した水
					if(visit[rr][cc]==false){//未使用
						visit[rr][cc] = true;
						fld[rr][cc] = color;
						temp[0] = rr;
						temp[1] = cc;
						next.push(temp);
					}
				}
			}
		}
	}
}
void solve(){
	
	cin>>R>>C;
	fld=vector<vector<int> >(R,vector<int>(C,0));
	for(int r=0;r<R;++r){
		for(int c=0;c<C;++c){
			int ter;
			cin>>ter;
			if(ter){
				fld[r][c]=-1;
			}
		}
	}

	int ans = 0;
	for(int r=0;r<R;++r){
		for(int c=0;c<C;++c){
			if(fld[r][c]==-1){
				++ans;
				cal(r,c,ans);
			}
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()
0