結果

問題 No.307 最近色塗る問題多くない?
ユーザー IL_msta
提出日時 2018-02-16 20:18:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,988 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 107,160 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-06-13 03:48:59
合計ジャッジ時間 6,908 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 <tuple>
#include <bitset>

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

#include <fstream>
#include <random>
//#include <time.h>
//#include <intrin.h>
#include <ctime>
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#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 H,W;
vector< vector<int> > field;
void solve(){
	cin >> H >> W;
	field = vector< vector<int> >(H+2,vector<int>(W+2,4));
	for(int h=0;h<H;++h){
		for(int w=0;w<W;++w){
			cin >> field[h+1][w+1];
		}
	}
	int Q;
	cin >> Q;
	int R,C,X;
	queue<int> posQ;
	vector<int> dir(4);
	dir[0] = 1;
	dir[1] = W+2;
	dir[2] = -1;
	dir[3] = -(W+2);
	int now;
	while(Q--){
		cin >> R >> C >> X;
		if( field[R][C] == X ) continue;
		int chang = field[R][C];
		field[R][C] = X;

		posQ.push( R*(W+2)+C);
		while(posQ.size()){
			now = posQ.front();
			posQ.pop();
			for(int k=0;k<4;++k){
				int temp = now + dir[k];
				int r = temp/(W+2);
				int c = temp%(W+2);
				if( field[r][c] == chang ){
					field[r][c] = X;
					posQ.push( temp );
				}
			}
		}
	}
	for(int h=0;h<H;++h){
		for(int w=0;w<W;++w){
			if(w)cout << ' ';
			cout << field[h+1][w+1];
		}
		cout << 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