結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 10 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 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 4 ms
5,376 KB
testcase_11 AC 90 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 16 ms
5,376 KB
testcase_32 AC 148 ms
5,376 KB
testcase_33 AC 24 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 161 ms
5,376 KB
testcase_37 AC 14 ms
5,376 KB
testcase_38 AC 239 ms
5,376 KB
testcase_39 AC 79 ms
5,376 KB
testcase_40 AC 133 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int cnt = h;
    rep(i, h) {
        int bs = 0;
        rep(j, w) bs += s[i][j] == '#';
        if (bs) {
            for(; i < h; i++) {
                int bs = 0;
                rep(j, w) bs += s[i][j] == '#';
                if (bs == 0 || bs == w) {
                    cout << "No\n";
                    return 0;
                }
            }
            break;
        }
        cnt--;
    }
    rep(s1, 1 << h) rep(s2, 1 << h) if ((s1 & s2) == 0 && __builtin_popcount(s1) == cnt) {
        vector<string> t(h, string(w, '.'));
        {
            int k = h - 1;
            rrep(i, h) if (s1 >> i & 1) {
                rep(j, w) t[i][j] = s[k][j];
                k--;
            }
        }
        rep(i, h) if (s2 >> i & 1) rep(j, w) t[i][j] = '#';
        int source = h * w, sink = source + 1;
        mf_graph<int> g(sink + 1);
        rep(i, h) rep(j, w) if (t[i][j] == '#') {
            if (i + j & 1) g.add_edge(i * w + j, sink, 1);
            else g.add_edge(source, i * w + j, 1);
        }
        for(int i = 0; i < h - 1; i++) for(int j = 0; j < w; j++) if ((i + j & 1) == 0 && t[i][j] == '#' && t[i+1][j] == '#') g.add_edge(i * w + j, (i + 1) * w + j, 1);
        for(int i = 1; i < h    ; i++) for(int j = 0; j < w; j++) if ((i + j & 1) == 0 && t[i][j] == '#' && t[i-1][j] == '#') g.add_edge(i * w + j, (i - 1) * w + j, 1);
        for(int i = 0; i < h; i++) for(int j = 0; j < w - 1; j++) if ((i + j & 1) == 0 && t[i][j] == '#' && t[i][j+1] == '#') g.add_edge(i * w + j, i * w + j + 1, 1);
        for(int i = 0; i < h; i++) for(int j = 1; j < w; j++)     if ((i + j & 1) == 0 && t[i][j] == '#' && t[i][j-1] == '#') g.add_edge(i * w + j, i * w + j - 1, 1);
        int f = g.flow(source, sink);
        int bcnt = 0;
        rep(i, h) rep(j, w) bcnt += t[i][j] == '#';
        if (f * 2 == bcnt) {
            char nxt_c = 'a';
            for(auto e: g.edges()) {
                if (e.from < h * w && e.to < h * w && e.flow) {
                    t[e.from / w][e.from % w] = t[e.to / w][e.to % w] = nxt_c;
                    if (nxt_c == 'z') nxt_c = 'A';
                    else nxt_c++;
                }
            }
            cout << "Yes\n";
            rep(i, h) cout << t[i] << '\n';
            return 0;
        }
    }
    cout << "No\n";
}
0