結果

問題 No.1427 Simplified Tetris
ユーザー 沙耶花沙耶花
提出日時 2021-03-12 22:53:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,099 bytes
コンパイル時間 4,633 ms
コンパイル使用メモリ 274,324 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-04 16:17:10
合計ジャッジ時間 6,830 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,388 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 16 ms
4,384 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 16 ms
4,376 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 21 ms
4,376 KB
testcase_39 AC 20 ms
4,376 KB
testcase_40 AC 15 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000
int H,W;
int get(int y,int x){
	return y*W+x;
}

pair<int,int> get(int v){
	return make_pair(v/W,v%W);
}

string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

void go(vector<string> S){
	/*
	rep(i,S.size()){
		cout<<S[i]<<endl;
	}
	*/
	
	int cnt = 0;
	mf_graph<int> G(H*W+2);
	int s = H*W,t = H*W+1;
	vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1};
	rep(i,H){
		rep(j,W){
			if(S[i][j]=='#')cnt++;
			else continue;
			if((i+j)%2==0){
				G.add_edge(s,get(i,j),1);
				rep(k,4){
					int y = i+dy[k],x = j + dx[k];
					if(y<0||y>=H||x<0||x>=W)continue;
					G.add_edge(get(i,j),get(y,x),1);
				}
			}
			else G.add_edge(get(i,j),t,1);
		}
	}
//	cout<<cnt<<endl;
	if(G.flow(s,t)*2!=cnt)return;
	int ind = 0;
	auto E = G.edges();
	for(auto e:E){
		if(e.from==s||e.to==t)continue;
		if(e.flow==0)continue;
		int u = e.from,v = e.to;
		auto A = get(u),B = get(v);
		if(S[A.first][A.second]!='#')continue;
		S[A.first][A.second] = alpha[ind];
		S[B.first][B.second] = alpha[ind];
		ind++;
	}
	cout<<"Yes"<<endl;
	rep(i,S.size()){
		cout<<S[i]<<endl;
	}
	exit(0);
	
}

int main(){
	
	
	cin>>H>>W;
	
	vector<string> S(H);
	rep(i,H)cin>>S[i];
	int u = -1,b = -1;
	rep(i,H){
		if(S[i]!=string(W,'.')){
			if(u==-1)u = i;
			b = i;
		}
	}
	
	rep(i,H){
		int c = 0;
		rep(j,W){
			if(S[i][j]=='.')c++;
		}
		if(c==0){
			cout<<"No"<<endl;
			return 0;
		}
	}

	if(u==-1){
		cout<<"Yes"<<endl;
		rep(i,H){
			cout<<S[i]<<endl;
		}
		return 0;
	}
	if(b!=H-1){
		cout<<"No"<<endl;
		return 0;
	}
	
	for(int j=u;j<=b;j++){
		if(S[j]==string(W,'.')){
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	rep(i,1<<H){
		int cur = H-1;
		vector<string> SS(H,string(W,'.'));
		for(int j=H-1;j>=0;j--){
			if((i>>j)&1){
				SS[j] = string(W,'#');
			}
			else{
				if(cur<u)continue;
				SS[j] = S[cur];
				cur--;
			}
		}
		if(cur>=u)continue;
		go(SS);
	}
	cout<<"No"<<endl;
	
    return 0;
}
0