結果

問題 No.1123 Afforestation
ユーザー 👑 kmjpkmjp
提出日時 2020-08-04 01:12:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,963 bytes
コンパイル時間 3,365 ms
コンパイル使用メモリ 217,000 KB
実行使用メモリ 104,060 KB
最終ジャッジ日時 2023-10-11 21:39:39
合計ジャッジ時間 22,800 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 109 ms
19,188 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 57 ms
13,644 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 2 ms
4,352 KB
testcase_73 AC 2 ms
4,352 KB
testcase_74 AC 2 ms
4,352 KB
testcase_75 AC 2 ms
4,352 KB
testcase_76 AC 2 ms
4,348 KB
testcase_77 AC 2 ms
4,348 KB
testcase_78 AC 2 ms
4,352 KB
testcase_79 AC 2 ms
4,352 KB
testcase_80 AC 1 ms
4,352 KB
testcase_81 AC 2 ms
4,348 KB
testcase_82 AC 2 ms
4,352 KB
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 AC 2 ms
4,352 KB
testcase_87 AC 2 ms
4,352 KB
testcase_88 AC 219 ms
103,936 KB
testcase_89 AC 217 ms
104,060 KB
testcase_90 AC 1 ms
4,348 KB
testcase_91 AC 2 ms
4,348 KB
testcase_92 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
int A[2020],B[2020],OA[2020],OB[2020];
int K;
int Y[16],X[16];
int R[2020][2020];
string S[2020];

template<class V> class MaxFlow_dinic {
public:
	struct edge { int to,reve;V cap;};
	static const int MV = 4200;
	vector<edge> E[MV];
	int itr[MV],lev[MV];
	void add_edge(int x,int y,V cap,V cap2) {
		E[x].push_back((edge){y,(int)E[y].size(),cap});
		E[y].push_back((edge){x,(int)E[x].size()-1,cap2});
	}
	void bfs(int cur) {
		MINUS(lev);
		queue<int> q;
		lev[cur]=0;
		q.push(cur);
		while(q.size()) {
			int v=q.front(); q.pop();
			ITR(e,E[v]) if(e->cap>0 && lev[e->to]<0) lev[e->to]=lev[v]+1, q.push(e->to);
		}
	}
	V dfs(int from,int to,V cf) {
		if(from==to) return cf;
		for(;itr[from]<E[from].size();itr[from]++) {
			edge* e=&E[from][itr[from]];
			if(e->cap>0 && lev[from]<lev[e->to]) {
				V f=dfs(e->to,to,min(cf,e->cap));
				if(f>0) {
					e->cap-=f;
					E[e->to][e->reve].cap += f;
					return f;
				}
			}
		}
		return 0;
	}
	V maxflow(int from, int to) {
		V fl=0,tf;
		while(1) {
			bfs(from);
			if(lev[to]<0) return fl;
			ZERO(itr);
			while((tf=dfs(from,to,numeric_limits<V>::max()))>0) fl+=tf;
		}
	}
};
MaxFlow_dinic<int> mf;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	vector<pair<int,int>> V;
	FOR(y,H) {
		cin>>A[y];
		OA[y]=A[y];
	}
	
	priority_queue<pair<int,int>> Q;
	FOR(x,W) {
		cin>>B[x];
		OB[x]=B[x];
		if(B[x]) Q.push({B[x],x});
	}
	
	FOR(y,H) {
		if(A[y]>Q.size()) return _P(":(\n");
		vector<int> V;
		FOR(x,A[y]) {
			i=Q.top().second;
			Q.pop();
			B[i]--;
			A[y]--;
			R[y][i]=1;
			V.push_back(i);
		}
		FORR(v,V) if(B[v]) Q.push({B[v],v});
	}
	
	if(Q.size()) return _P(":(\n");

	FOR(y,H) S[y]=string(W,'.');
	
	int add=0;
	cin>>K;
	FOR(i,K) {
		cin>>Y[i]>>X[i];
		Y[i]--,X[i]--;
		if(R[Y[i]][X[i]]) {
			A[Y[i]]++;
			B[X[i]]++;
			add++;
		}
		R[Y[i]][X[i]]=-1;
		S[Y[i]][X[i]]='x';
	}
	
	FOR(y,H) {
		mf.add_edge(4010,y,A[y],OA[y]-A[y]);
		FOR(x,W) {
			if(R[y][x]==0) mf.add_edge(y,2000+x,1,0);
			else if(R[y][x]==1) mf.add_edge(y,2000+x,0,1);
		}
	}
	FOR(x,W) {
		mf.add_edge(2000+x,4011,B[x],OB[x]-B[x]);
	}
	
	if(mf.maxflow(4010,4011)!=add) return _P(":(\n");
	
	cout<<"Yay!"<<endl;
	FOR(y,H) {
		FORR(e,mf.E[y]) if(e.to>=2000 && e.to<4000 && e.cap==0) S[y][e.to-2000]='o';
		cout<<S[y]<<endl;
	}
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0