結果

問題 No.1123 Afforestation
ユーザー chocoruskchocorusk
提出日時 2020-08-01 17:32:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,127 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 142,776 KB
実行使用メモリ 220,296 KB
最終ジャッジ日時 2023-09-22 11:09:52
合計ジャッジ時間 17,729 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,808 KB
testcase_04 AC 16 ms
13,964 KB
testcase_05 AC 143 ms
62,340 KB
testcase_06 AC 661 ms
219,764 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,488 KB
testcase_11 AC 9 ms
7,072 KB
testcase_12 AC 78 ms
34,708 KB
testcase_13 AC 805 ms
220,296 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,652 KB
testcase_19 AC 20 ms
14,064 KB
testcase_20 AC 197 ms
62,140 KB
testcase_21 AC 816 ms
219,560 KB
testcase_22 AC 821 ms
219,516 KB
testcase_23 AC 809 ms
219,904 KB
testcase_24 AC 815 ms
219,868 KB
testcase_25 AC 810 ms
219,716 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 4 ms
4,708 KB
testcase_35 AC 3 ms
4,744 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 4 ms
4,700 KB
testcase_40 AC 4 ms
4,704 KB
testcase_41 AC 4 ms
4,740 KB
testcase_42 AC 10 ms
6,988 KB
testcase_43 AC 20 ms
13,976 KB
testcase_44 AC 36 ms
18,208 KB
testcase_45 AC 37 ms
18,340 KB
testcase_46 AC 45 ms
19,820 KB
testcase_47 AC 45 ms
19,760 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 4 ms
4,692 KB
testcase_51 AC 4 ms
4,752 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 4 ms
4,696 KB
testcase_56 AC 4 ms
4,712 KB
testcase_57 AC 4 ms
4,952 KB
testcase_58 AC 10 ms
6,972 KB
testcase_59 AC 20 ms
13,968 KB
testcase_60 AC 37 ms
18,244 KB
testcase_61 AC 37 ms
18,272 KB
testcase_62 AC 44 ms
19,720 KB
testcase_63 AC 45 ms
19,748 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 2 ms
4,376 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 4 ms
4,956 KB
testcase_69 AC 7 ms
6,072 KB
testcase_70 AC 10 ms
6,924 KB
testcase_71 AC 20 ms
13,736 KB
testcase_72 WA -
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 2 ms
4,380 KB
testcase_75 AC 1 ms
4,376 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 1 ms
4,376 KB
testcase_78 AC 2 ms
4,380 KB
testcase_79 AC 1 ms
4,376 KB
testcase_80 AC 2 ms
4,380 KB
testcase_81 AC 2 ms
4,380 KB
testcase_82 AC 2 ms
4,380 KB
testcase_83 AC 1 ms
4,376 KB
testcase_84 AC 429 ms
219,828 KB
testcase_85 AC 511 ms
219,908 KB
testcase_86 AC 2 ms
4,376 KB
testcase_87 AC 2 ms
4,376 KB
testcase_88 AC 411 ms
204,012 KB
testcase_89 AC 424 ms
204,112 KB
testcase_90 AC 1 ms
4,376 KB
testcase_91 AC 1 ms
4,376 KB
testcase_92 AC 2 ms
4,380 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>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e18;
struct edge {int to; ll cap; int rev;} ;

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

void add_edge(int from, int to, ll cap, ll myon=0){
	edge e;
	e.to=to, e.cap=cap-myon, e.rev=G[to].size();
	G[from].push_back(e);
	e.to=from, e.cap=myon, 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;
		}
	}
}
int z[2020][2020];
int main()
{
	int h, w; cin>>h>>w;
	int a[2020], b[2020];
	vector<P> va(h);
	int sa=0, sb=0;
	for(int i=0; i<h; i++){
		cin>>a[i];
		sa+=a[i];
		va[i]=P(a[i], i);
	}
	for(int i=0; i<w; i++){
		cin>>b[i];
		sb+=b[i];
	}
	if(sa!=sb){
		cout<<":("<<endl;
		return 0;
	}
	sort(va.begin(), va.end(), greater<P>());
	int cnt[2020]={};
	for(auto p:va){
		int i=p.second;
		vector<P> vb(w);
		for(int j=0; j<w; j++) vb[j]=P(b[j]-cnt[j], j);
		sort(vb.begin(), vb.end(), greater<P>());
		for(int j=0; j<p.first; j++){
			z[i][vb[j].second]=1;
			cnt[vb[j].second]++;
		}
	}
	string ans[2020];
	for(int i=0; i<h; i++) for(int j=0; j<w; j++) ans[i]+='.';
	int k; cin>>k;
	int x[20], y[20];
	for(int i=0; i<k; i++){
		cin>>x[i]>>y[i];
		x[i]--; y[i]--;
		ans[x[i]][y[i]]='x';
	}
	int a1[2020]={}, b1[2020]={};
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(z[i][j] && ans[i][j]!='x'){
				a1[i]++, b1[j]++;
			}
		}
	}
	int s=h+w, t=s+1;
	int sa1=0;
	for(int i=0; i<h; i++){
		add_edge(s, i, a[i], a1[i]);
		sa1+=a1[i];
	}
	for(int i=0; i<w; i++){
		add_edge(i+h, t, b[i], b1[i]);
	}
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(ans[i][j]=='x') continue;
			add_edge(i, j+h, 1, z[i][j]);
		}
	}
	int f=max_flow(s, t);
	if(f<sa-sa1){
		cout<<":("<<endl;
		return 0;
	}
	cout<<"Yay!"<<endl;
	for(int i=0; i<h; i++){
		for(auto e:G[i]){
			if(e.to==s) continue;
			if(e.cap==0){
				ans[i][e.to-h]='o';
			}
		}
	}
	for(int i=0; i<h; i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}
0