結果

問題 No.697 池の数はいくつか
ユーザー ohreitetsuohreitetsu
提出日時 2018-06-10 13:57:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,425 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 71,996 KB
実行使用メモリ 11,588 KB
最終ジャッジ日時 2023-08-16 22:17:45
合計ジャッジ時間 10,175 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int H,W;
int ans=0;
bool not1(vector<vector<int>> A)
{
	int i,j;
	for (i=1;i<=H;i++){
		for (j=1;j<=W;j++){
			if (A[i][j]==1){
				return false;
			}
		}
	}
	return true;
}
void check(vector<vector<int>> &A,int I,int J,int &index)
{
	if (A[I][J]==1){
		ans++;
		index++;
		A[I][J]=index;
		if (A[I-1][J]==1){
			A[I-1][J]=index;
		}
		if (A[I+1][J]==1){
			A[I+1][J]=index;
		}
		if (A[I][J-1]==1){
			A[I][J-1]=index;
		}
		if (A[I][J+1]==1){
			A[I][J+1]=index;
		}
		int i,j;
		for (i=I;i<=H;i++){
			for (j=J+1;j<=W;j++){
				if (A[i][j]==0 ){
					continue;
				}
				if (A[i-1][j]==index || A[i+1][j]==index || A[i][j-1]==index || A[i][j+1]==index){
					A[i][j]=index;
					if (A[i-1][j]==1){
						A[i-1][j]=index;
					}
					if (A[i+1][j]==1){
						A[i+1][j]=index;
					}
					if (A[i][j-1]==1){
						A[i][j-1]=index;
					}
					if (A[i][j+1]==1){
						A[i][j+1]=index;
					}
				}
			}
		}
	}	
}
int main(int argc, char* argv[])
{
	cin>>H>>W;
	int n0=0,n1=0;
	vector<vector<int>> A(H+2,vector<int>(W+2));
	int i,j;
	for (i=1;i<=H;i++){
		for (j=1;j<=W;j++){
			cin>>A[i][j];
			if (A[i][j]==0){
				n0++;
			}else{
				n1++;
			}
		}
	}
	if (n0==H*W){
		cout<<0<<endl;
		return 0;
	}
	if (n1==H*W){
		cout<<1<<endl;
		return 0;
	}
	int index=1;
	for (i=1;i<=H;i++){
		for (j=1;j<=W;j++){
			check(A,i,j,index);
		}
	}
	cout<<ans<<endl;
	return 0;
}
0