結果

問題 No.1427 Simplified Tetris
ユーザー KudeKude
提出日時 2021-03-13 00:00:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,985 bytes
コンパイル時間 5,810 ms
コンパイル使用メモリ 266,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 15:16:29
合計ジャッジ時間 8,322 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 10 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 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 89 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 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 4 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
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 150 ms
5,376 KB
testcase_33 AC 25 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 WA -
testcase_36 AC 162 ms
5,376 KB
testcase_37 AC 15 ms
5,376 KB
testcase_38 AC 246 ms
5,376 KB
testcase_39 AC 85 ms
5,376 KB
testcase_40 AC 137 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) {
        bool ok = true;
        rep(j, w) ok &= s[i][j] == '.';
        if (!ok) {
            for(i++; i < h; i++) {
                bool ok = true;
                rep(j, w) ok &= s[i][j] == '.';
                if (ok) {
                    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