結果

問題 No.1427 Simplified Tetris
ユーザー SSRSSSRS
提出日時 2021-03-13 00:23:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,000 bytes
コンパイル時間 2,231 ms
コンパイル使用メモリ 180,388 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 15:40:56
合計ジャッジ時間 3,960 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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, '.');
    }
    cout << 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;
      }
    }
  }
}
0