結果

問題 No.1427 Simplified Tetris
ユーザー chocoruskchocorusk
提出日時 2021-03-12 23:15:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,777 bytes
コンパイル時間 4,024 ms
コンパイル使用メモリ 192,028 KB
実行使用メモリ 9,792 KB
最終ジャッジ日時 2024-04-22 14:47:28
合計ジャッジ時間 9,031 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

const ll INF=1e18;
struct edge {int to; ll cap; int rev;} ;

vector<edge> G[200020];
int level[200020];
int iter[200020];

void add_edge(int from, int to, ll cap){
	edge e;
	e.to=to, e.cap=cap, e.rev=G[to].size();
	G[from].push_back(e);
	e.to=from, e.cap=0, e.rev=G[from].size()-1;
	G[to].push_back(e);
}

void bfs(int s){
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0; i<G[v].size(); i++){
			edge e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

ll dfs(int v, int t, ll f){
	if(v==t) return f;
	for(int &i=iter[v]; i<G[v].size(); i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			ll d=dfs(e.to, t, min(f, e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(int s, int t){
	ll flow=0;
	while(1){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter, 0, sizeof(iter));
		ll f;
		while((f=dfs(s, t, INF))>0){
			flow+=f;
		}
	}
}
string s[10];
string moji;
int main()
{
    int h, w; cin>>h>>w;
    for(int i=0; i<h; i++){
        cin>>s[i];
    }
    cout<<"No"<<endl;
    return 0;
    for(char c='A'; c<='Z'; c++) moji+=c;
    for(char c='a'; c<='z'; c++) moji+=c;
    bool exist[10]={};
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j]=='#') exist[i]=1;
        }
    }
    for(int i=0; i<h-1; i++){
        if(exist[i] && !exist[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    int l=-1;
    for(int i=0; i<h; i++){
        if(exist[i]){
            l=i; break;
        }
    }
    if(l==-1){
        cout<<"Yes"<<endl;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++) cout<<'.';
            cout<<endl;
        }
        return 0;
    }
    for(int i=0; i<(1<<h); i++){
        if(h-l!=popcount(i)) continue;
        string s1[10];
        for(int j=0; j<h; j++) for(int k=0; k<w; k++) s1[j]+='.';
        int j1=l;
        int l1=-1;
        for(int j=0; j<h; j++){
            if(i&(1<<j)){
                s1[j]=s[j1++];
                if(l1==-1) l1=j;
            }else if(j1>l){
                s1[j].clear();
                for(int k=0; k<w; k++) s1[j]+='#';
            }
        }
        auto solve=[&](){
            int a=h*w, b=h*w+1;
            for(int j=0; j<h*w+2; j++){
                G[j].clear();
            }
            int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};
            int c1=0, c2=0;
            for(int j=0; j<h; j++){
                for(int k=0; k<w; k++){
                    if(s1[j][k]=='.') continue;
                    if((j+k)%2==0) add_edge(a, j*w+k, 1), c1++;
                    else add_edge(j*w+k, b, 1), c2++;
                    if((j+k)%2==0){
                        for(int p=0; p<4; p++){
                            int x1=j+dx[p], y1=k+dy[p];
                            if(x1>=0 && x1<h && y1>=0 && y1<w){
                                add_edge(j*w+k, x1*w+y1, 1);
                            }
                        }
                    }
                }
            }
            if(c1!=c2) return false;
            int f=max_flow(a, b);
            if(f<c1) return false;
            cout<<"Yes"<<endl;
            int m=0;
            for(int j=0; j<h; j++){
                for(int k=0; k<w; k++){
                    if(s1[j][k]=='.' || (j+k)%2!=0) continue;
                    int x=j*w+k;
                    for(auto e:G[x]){
                        int y=e.to;
                        if(y>=h*w) continue;
                        if(e.cap==0){
                            s1[j][k]=moji[m];
                            s1[y/w][y%w]=moji[m++];
                        }
                    }
                }
            }
            for(int j=0; j<h; j++){
                cout<<s1[j]<<endl;
            }
            return true;
        };
        if(solve()) return 0;
        for(int j=l1-1; j>=0; j--){
            s1[j].clear();
            for(int k=0; k<w; k++) s1[j]+='#';
            if(solve()) return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}
0