結果
| 問題 |
No.1427 Simplified Tetris
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2021-03-13 00:03:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 253 ms / 2,000 ms |
| コード長 | 2,989 bytes |
| コンパイル時間 | 5,317 ms |
| コンパイル使用メモリ | 262,760 KB |
| 最終ジャッジ日時 | 2025-01-19 15:58:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
#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";
}
Kude