結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 07:12:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 699 ms / 4,000 ms
コード長 1,700 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 75,128 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-14 03:44:00
合計ジャッジ時間 7,475 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 50 ms
4,380 KB
testcase_09 AC 22 ms
4,380 KB
testcase_10 AC 18 ms
4,380 KB
testcase_11 AC 45 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 49 ms
4,380 KB
testcase_18 AC 105 ms
4,376 KB
testcase_19 AC 77 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 104 ms
4,376 KB
testcase_22 AC 68 ms
4,376 KB
testcase_23 AC 553 ms
4,376 KB
testcase_24 AC 347 ms
4,376 KB
testcase_25 AC 511 ms
4,380 KB
testcase_26 AC 695 ms
4,376 KB
testcase_27 AC 296 ms
4,376 KB
testcase_28 AC 173 ms
4,376 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 699 ms
4,380 KB
testcase_31 AC 285 ms
4,380 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 186 ms
4,380 KB
testcase_34 AC 17 ms
4,380 KB
testcase_35 AC 192 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <string>
#include <algorithm>

using namespace std;
typedef bitset<62750> bits;

int h,w;

int main_(){
	scanf("%d%d", &h,&w);
	vector<vector<int>> a(h, vector<int>(w));
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			scanf("%d", &a[i][j]);
		}
	}

	bits s;
	bits filter;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			int pos = i*(w+1) + j;
			if(a[i][j]) s.set(pos);
			filter.set(pos);
		}
	}

	auto dbg = [&](){

		string tmp = s.to_string();
		reverse(tmp.begin(), tmp.end());
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				printf("%c%s", tmp[i*(w+1)+j], (j==w-1)?"\n":" ");
			}
		}
		puts("");
	};

	bool filled = false;
	int last = -1;

	int q;
	scanf("%d", &q);
	while(q--){
		int r,c,x;
		scanf("%d%d%d", &r,&c,&x);
		r--; c--;

		last = x;
		if(filled) continue;

		if(x == s[r*(w+1)+c]) continue;

		bits z;
		z.set(r*(w+1) + c);
		if(x==0){
			while(1){
				bits last = z;
				z |= ((z<<1) | (z>>1) | (z<<(w+1)) | (z>>(w+1))) & s;
				
				if(z == last) break;
			}
		}else{
			bits ns = (~s & filter);
			while(1){
				bits last = z;
				z |= ((z<<1) | (z>>1) | (z<<(w+1)) | (z>>(w+1))) & ns;
				
				if(z == last) break;
			}
		}
		s ^= z;
		int cnt = s.count();
		filled = cnt == 0 || cnt == h*w;

		//dbg();
	}

	if(filled){
		s.reset();
		if(last == 1) s.flip();
	}

	string tmp = s.to_string();
	reverse(tmp.begin(), tmp.end());
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			printf("%c%s", tmp[i*(w+1)+j], (j==w-1)?"\n":" ");
		}
	}
	return 0;
}

int main(){
	auto start = clock();
	main_();
	cerr << clock() - start << " [ms]" << endl;
	return 0;
}
0