結果
| 問題 |
No.1427 Simplified Tetris
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-03-13 00:25:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,990 bytes |
| コンパイル時間 | 2,024 ms |
| コンパイル使用メモリ | 185,684 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-14 14:47:42 |
| 合計ジャッジ時間 | 4,052 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int H, W;
cin >> H >> W;
vector<string> s(H);
for (int i = H - 1; i >= 0; i--){
cin >> s[i];
}
int mx = H;
bool ok = true;
for (int i = H - 1; i >= 0; i--){
bool ok1 = false, ok2 = false;
for (int j = 0; j < W; j++){
if (s[i][j] == '.'){
ok1 = true;
}
if (s[i][j] == '#'){
ok2 = true;
}
}
if (!ok1){
ok = false;
}
if (ok2 && mx == H){
mx = i;
}
if (!ok2 && mx != H){
ok = false;
}
}
if (!ok){
cout << "No" << endl;
} else if (mx == H){
cout << "Yes" << endl;
for (int i = 0; i < H; i++){
cout << string(W, '.') << endl;
}
} else {
int cnt = mx + 1;
bool ok2 = false;
vector<string> ans;
for (int i = 0; i < (1 << H); i++){
if (__builtin_popcount(i) == cnt){
vector<int> p;
for (int j = 0; j < H; j++){
if ((i >> j & 1) == 1){
p.push_back(j);
}
}
vector<string> s2(H, string(W, '.'));
for (int j = 0; j < p[cnt - 1]; j++){
s2[j] = string(W, '#');
}
for (int j = 0; j < cnt; j++){
s2[p[j]] = s[j];
}
vector<vector<bool>> dp(H * W + 1, vector<bool>(1 << W, false));
dp[0][(1 << W) - 1] = true;
for (int j = 0; j < H * W; j++){
for (int k = 0; k < (1 << W); k++){
if (dp[j][k]){
int x = j / W, y = j % W;
if (s2[x][y] == '.'){
if ((k >> (W - 1) & 1) == 1){
int k2 = k - (1 << (W - 1));
dp[j + 1][k2 * 2 + 1] = true;
}
} else {
if ((k >> (W - 1) & 1) == 1){
int k2 = k - (1 << (W - 1));
dp[j + 1][k2 * 2] = true;
if (y > 0){
if ((k & 1) == 0){
dp[j + 1][k2 * 2 + 3] = true;
}
}
} else {
dp[j + 1][k * 2 + 1] = true;
}
}
}
}
}
if (dp[H * W][(1 << W) - 1]){
ok2 = true;
vector<char> c;
for (int j = 0; j < 26; j++){
c.push_back('a' + j);
}
for (int j = 0; j < 26; j++){
c.push_back('A' + j);
}
int id = 0;
int S = (1 << W) - 1;
for (int j = H * W - 1; j >= 0; j--){
int x = j / W, y = j % W;
if ((S & 1) == 0){
if (dp[j][S / 2]){
S = S / 2;
} else {
S = S / 2 + (1 << (W - 1));
}
} else if (s2[x][y] == '.'){
if (dp[j][(S - 1) / 2]){
S = (S - 1) / 2;
} else {
S = (S - 1) / 2 + (1 << (W - 1));
}
} else {
bool h = false;
if (y > 0){
if (s2[x][y - 1] == '#'){
if ((S >> 1 & 1) == 1){
if (dp[j][(S - 3) / 2]){
S = (S - 3) / 2;
h = true;
} else if (dp[j][(S - 3) / 2 + (1 << (W - 1))]){
S = (S - 3) / 2 + (1 << (W - 1));
h = true;
}
}
}
}
if (h){
s2[x][y] = c[id];
s2[x][y - 1] = c[id];
id++;
} else {
s2[x][y] = c[id];
s2[x - 1][y] = c[id];
id++;
S = (S - 1) / 2;
}
}
}
ans = s2;
break;
}
}
}
if (!ok2){
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = H - 1; i >= 0; i--){
cout << ans[i] << endl;
}
}
}
}
SSRS