結果
問題 | No.1427 Simplified Tetris |
ユーザー | leaf_1415 |
提出日時 | 2021-03-12 23:49:22 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 5,460 bytes |
コンパイル時間 | 1,001 ms |
コンパイル使用メモリ | 99,384 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 14:15:55 |
合計ジャッジ時間 | 2,598 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 7 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 3 ms
5,248 KB |
testcase_11 | AC | 21 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 1 ms
5,248 KB |
testcase_18 | AC | 1 ms
5,248 KB |
testcase_19 | AC | 7 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 1 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 1 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 3 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 4 ms
5,248 KB |
testcase_32 | AC | 53 ms
5,248 KB |
testcase_33 | AC | 4 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 34 ms
5,248 KB |
testcase_37 | AC | 3 ms
5,248 KB |
testcase_38 | AC | 62 ms
5,248 KB |
testcase_39 | AC | 22 ms
5,248 KB |
testcase_40 | AC | 36 ms
5,248 KB |
ソースコード
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #include <complex> #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define sz(x) ((ll)(x).size()) #define ceil(x, y) (((x)+(y)-1) / (y)) #define all(x) (x).begin(),(x).end() #define outl(...) dump_func(__VA_ARGS__) #define inf 1e18 using namespace std; typedef long long llint; typedef long long ll; typedef pair<ll, ll> P; bool exceed(ll x, ll y, ll m){return x >= m / y + 1;} struct edge{ ll to, cost; edge(){} edge(ll a, ll b){ to = a, cost = b; } }; template<typename T> ostream& operator << (ostream& os, vector<T>& vec) { for(int i = 0; i<vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : " "); } return os; } template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U>& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& map_var) { for(typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ","; itr--; } return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) { for(typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << " "; itr--; } return os; } void dump_func() {cout << endl;} template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { cout << head; if(sizeof...(Tail) > 0) cout << " "; dump_func(std::move(tail)...); } struct Dinic{ struct edge{ llint to, cap, rev; edge(llint a, llint b, llint c){ to = a, cap = b, rev = c; } }; int n; vector<vector<edge> > G; vector<llint> level, iter; Dinic(){} Dinic(int n){ this->n = n; G.resize(n+1); level.resize(n+1); iter.resize(n+1); } void init(){ for(int i = 0; i <= n; i++) G[i].clear(); } void add_edge(int s, int t, llint cap) { G[s].push_back(edge(t, cap, G[t].size())); G[t].push_back(edge(s, 0, G[s].size()-1)); } void bfs(int s) { for(int i = 0; i <= n; i++) level[i] = inf; level[s] = 0; queue<int> Q; Q.push(s); while(Q.size()){ int v = Q.front(); Q.pop(); for(int i = 0; i < G[v].size(); i++){ int u = G[v][i].to; if(G[v][i].cap <= 0 || level[u] < inf) continue; level[u] = level[v] + 1; Q.push(u); } } } llint dfs(int v, llint f, int t) { if(v == t) return f; llint ret; for(llint &i = iter[v]; i < G[v].size(); i++){ if(level[v] >= level[G[v][i].to] || G[v][i].cap <= 0) continue; ret = dfs(G[v][i].to, min(f, G[v][i].cap), t); if(ret > 0){ G[v][i].cap -= ret; G[G[v][i].to][G[v][i].rev].cap += ret; return ret; } } return 0; } llint calc(int s, int t) { llint ret = 0, flow; while(1){ bfs(s); if(level[t] >= inf) break; for(int i = 0; i <= n; i++) iter[i] = 0; while(1){ flow = dfs(s, inf, t); if(flow <= 0) break; ret += flow; } } return ret; } }; ll h, w, maxh; char c[15][15]; char d[15][15]; ll dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; Dinic dc(305); ll ans[15][15]; void dfs(int p, int q) { if(p == h+1){ if(q <= maxh) return; ll S = h*w+w+1, T = S+1; dc.init(); ll lcnt = 0, rcnt = 0; rep(y, 1, h) rep(x, 1, w){ ll v = y*w+x; if((x+y)%2 == 0){ if(d[x][y] == '#') dc.add_edge(S, v, 1), lcnt++; rep(i, 0, 3){ ll nx = x + dx[i], ny = y + dy[i]; if(nx < 1 || nx > w || ny < 1 || ny > h) continue; ll nv = ny*w+nx; dc.add_edge(v, nv, 1); } } else if(d[x][y] == '#') dc.add_edge(v, T, 1), rcnt++; } if(lcnt != rcnt) return; /*for(int y = h; y >= 1; y--){ rep(x, 1, w) cout << d[x][y]; cout << endl; } cout << endl;*/ if(dc.calc(S, T) != lcnt) return; ll id = 0; rep(y, 1, h) rep(x, 1, w){ ll v = y*w+x; if((x+y)%2 == 0) continue; if(d[x][y] != '#') continue; for(auto e : dc.G[v]){ if(e.cap == 0) continue; ll nx = (e.to-1) % w + 1, ny = (e.to-1) / w; ans[x][y] = ans[nx][ny] = id++; } } outl("Yes"); for(int y = h; y >= 1; y--){ rep(x, 1, w){ if(d[x][y] == '.') cout << '.'; else if(ans[x][y] < 26) cout << (char)('a'+ans[x][y]); else cout << (char)('A'+ans[x][y]-26); } cout << endl; } exit(0); } if(q <= maxh){ rep(x, 1, w) d[x][p] = c[x][q]; dfs(p+1, q+1); } rep(x, 1, w) d[x][p] = '#'; dfs(p+1, q); rep(x, 1, w) d[x][p] = '.'; dfs(p+1, q); } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for(int y = h; y >= 1; y--){ rep(x, 1, w) cin >> c[x][y]; } rep(y, 1, h) rep(x, 1, w) if(c[x][y] == '#') chmax(maxh, y); rep(y, 1, maxh){ bool flag = false; rep(x, 1, w) if(c[x][y] == '#') flag = true; if(!flag){ outl("No"); return 0; } flag = false; rep(x, 1, w) if(c[x][y] == '.') flag = true; if(!flag){ outl("No"); return 0; } } dfs(1, 1); outl("No"); return 0; }