結果

問題 No.13 囲みたい!
ユーザー kotatsugamekotatsugame
提出日時 2019-10-14 12:27:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 830 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 74,416 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 02:31:25
合計ジャッジ時間 1,766 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 4 ms
4,384 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
int H,W;
int M[100][100];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int used[100][100];
main()
{
	cin>>W>>H;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>M[i][j];
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)
	{
		if(used[i][j])continue;
		used[i][j]=1;
		int vc=1,ec=0;
		queue<pair<int,int> >P;
		P.push(make_pair(i,j));
		while(!P.empty())
		{
			int x=P.front().first,y=P.front().second;
			P.pop();
			used[x][y]=2;
			for(int r=0;r<4;r++)
			{
				int tx=x+dx[r],ty=y+dy[r];
				if(tx>=0&&ty>=0&&tx<H&&ty<W&&used[tx][ty]<2&&M[tx][ty]==M[i][j])
				{
					ec++;
					if(used[tx][ty]==0)
					{
						vc++;
						used[tx][ty]=1;
						P.push(make_pair(tx,ty));
					}
				}
			}
		}
		if(vc<=ec)
		{
			cout<<"possible"<<endl;
			return 0;
		}
	}
	cout<<"impossible"<<endl;
}
0