結果

問題 No.307 最近色塗る問題多くない?
ユーザー kotatsugamekotatsugame
提出日時 2019-10-14 03:56:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 4,000 ms
コード長 908 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 75,520 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 11:05:08
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 26 ms
4,376 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 21 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 13 ms
4,376 KB
testcase_18 AC 32 ms
4,376 KB
testcase_19 AC 29 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 25 ms
4,376 KB
testcase_22 AC 23 ms
4,376 KB
testcase_23 AC 146 ms
4,376 KB
testcase_24 AC 59 ms
4,376 KB
testcase_25 AC 100 ms
4,376 KB
testcase_26 AC 178 ms
4,376 KB
testcase_27 AC 22 ms
4,376 KB
testcase_28 AC 37 ms
4,380 KB
testcase_29 AC 15 ms
4,376 KB
testcase_30 AC 183 ms
4,376 KB
testcase_31 AC 38 ms
4,376 KB
testcase_32 AC 35 ms
4,380 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 36 ms
4,384 KB
testcase_35 AC 36 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
int used[200][200];
int A[200][200];
int H,W;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
main()
{
	cin>>H>>W;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>A[i][j];
	int Q;cin>>Q;
	bool flag=false,tx;
	for(int t=0;t++<Q;)
	{
		int r,c,x;cin>>r>>c>>x;r--,c--;
		if(flag)
		{
			tx=x;
			continue;
		}
		int y=A[r][c];
		if(x==y)continue;
		A[r][c]=x;
		queue<pair<int,int> >P;
		P.push(make_pair(r,c));
		used[r][c]=t;
		int cnt=0;
		while(!P.empty())
		{
			int nx=P.front().first,ny=P.front().second;P.pop();
			cnt++;
			for(int R=0;R<4;R++)
			{
				int tx=nx+dx[R],ty=ny+dy[R];
				if(tx>=0&&ty>=0&&tx<H&&ty<W&&used[tx][ty]<t&&A[tx][ty]==y)
				{
					A[tx][ty]=x;
					used[tx][ty]=t;
					P.push(make_pair(tx,ty));
				}
			}
		}
		if(cnt==H*W)flag=true,tx=x;
	}
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)cout<<(flag?tx:A[i][j])<<(j==W-1?"\n":" ");
}
0