結果

問題 No.1427 Simplified Tetris
ユーザー kwm_tkwm_t
提出日時 2021-03-13 18:06:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 3,229 bytes
コンパイル時間 4,005 ms
コンパイル使用メモリ 238,360 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 08:42:17
合計ジャッジ時間 6,323 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 18 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 76 ms
6,940 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 13 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 4 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 13 ms
6,944 KB
testcase_32 AC 126 ms
6,940 KB
testcase_33 AC 23 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 142 ms
6,940 KB
testcase_37 AC 71 ms
6,944 KB
testcase_38 AC 199 ms
6,940 KB
testcase_39 AC 72 ms
6,940 KB
testcase_40 AC 113 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int H, W;
	cin >> H >> W;
	vector<string>S(H);
	rep(i, H) { cin >> S[i]; }
	reverse(all(S));
	int brank = 0;
	vector<int>list;
	rep(i, H) {
		int block = 0;
		rep(j, W) {
			if ('#' == S[i][j]) {
				block++;
			}
		}
		if (W == block) {
			//不正入力を殺す
			cout << "No" << endl;
			return 0;
		}
		if (0 == block) {
			brank++;
			continue;
		}
		if (brank) {
			//不正入力を殺す
			cout << "No" << endl;
			return 0;
		}
		list.push_back(i);
	}
	//cout << list.size() << endl;
	int limit3 = 1;
	rep(i, H) { limit3 *= 3; }
	//cout << limit3 << endl;
	vector<char>C(52);
	rep(i, 26) {
		C[i] = 'a' + i;
		C[i + 26] = 'A' + i;
	}
	rep(i, limit3) {
		//if (20 != i) { continue; }
		vector<int>X(H);
		int copyi = i;
		int count0 = 0;
		rep(j, H) {
			X[j] = copyi % 3;
			copyi /= 3;
			if (0 == X[j]) { count0++; }
		}
		if (count0 != list.size()) { continue; }
		vector<string>newS(H);
		int now = 0;
		rep(j, H) {
			if (0 == X[j]) {
				newS[j] = S[list[now]];
				now++;
			}
			else if (1 == X[j]) {
				rep(k, W) { newS[j] += '.'; }
			}
			else {
				rep(k, W) { newS[j] += '#'; }
			}
		}
		reverse(all(newS));
		/*cout << i << endl;
		rep(j, H) {
			cout << newS[j] << endl;
		}
		cout << endl;*/
		mf_graph<int>g(H * W + 2);
		int s = H * W;
		int t = H * W + 1;
		int count = 0;
		rep(j, H) {
			rep(k, W) {
				if ('#' != newS[j][k]) { continue; }
				count++;
				int v = j * W + k;
				if (0 == (j + k) % 2) {
					g.add_edge(s, v, 1);
				}
				else {
					g.add_edge(v, t, 1);
				}
			}
		}
		rep(j, H) {
			rep(k, W) {
				if ('#' != newS[j][k]) { continue; }
				int v = j * W + k;
				if (1 == (j + k) % 2) { continue; }
				if ((j) && ('#' == newS[j - 1][k])) {
					int w = (j - 1)*W + k;
					g.add_edge(v, w, 1);
				}
				if ((k) && ('#' == newS[j][k - 1])) {
					int w = j * W + (k - 1);
					g.add_edge(v, w, 1);
				}
				if ((j + 1 < H) && ('#' == newS[j + 1][k])) {
					int w = (j + 1)*W + k;
					g.add_edge(v, w, 1);
				}
				if ((k + 1 < W) && ('#' == newS[j][k + 1])) {
					int w = j * W + (k + 1);
					g.add_edge(v, w, 1);
				}
			}
		}
		int fl = g.flow(s, t);
		if (2 * fl == count) {
			cout << "Yes" << endl;
			auto edges = g.edges();
			int num = 0;
			for (auto e : edges) {
				if (s == e.from) {continue;}
				if (t == e.to) {continue;}
				if (0 == e.flow) {continue;}
				int i0 = e.from / W;
				int j0 = e.from % W;
				int i1 = e.to / W;
				int j1 = e.to % W;
				newS[i0][j0] = C[num];
				newS[i1][j1] = C[num];
				num++;
			}
			rep(j, H) {
				cout << newS[j] << endl;
			}
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}
0