結果

問題 No.957 植林
ユーザー 👑tozangezan👑tozangezan
提出日時 2019-12-20 01:06:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,302 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 86,416 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-21 07:54:26
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 10 ms
4,376 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 AC 10 ms
4,376 KB
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 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
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 AC 9 ms
4,380 KB
testcase_42 AC 9 ms
4,376 KB
testcase_43 AC 14 ms
4,376 KB
testcase_44 AC 14 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 210000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long p[310][310];
long long q[310];
long long r[310];
int Q[310];
int R[310];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%lld",&p[i][j]);
	for(int i=0;i<a;i++)scanf("%lld",q+i);
	for(int i=0;i<b;i++)scanf("%lld",r+i);
	long long ret=0;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			q[i]-=p[i][j];
			r[j]-=p[i][j];
		}
	}
	while(1){
		bool upd=false;
		for(int i=0;i<a;i++){
			if(!Q[i]&&q[i]>=0){
				ret+=q[i];
				Q[i]=1;
				for(int j=0;j<b;j++){
					r[j]+=p[i][j];
				}
				upd=true;
				goto wolf;
			}
		}
		for(int i=0;i<b;i++){
			if(!R[i]&&r[i]>=0){
				ret+=r[i];
				R[i]=1;
				for(int j=0;j<a;j++){
					q[j]+=p[j][i];
				}
				upd=true;
				goto wolf;
			}
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(!Q[i]&&!R[j]&&q[i]+r[j]+p[i][j]>=0){
					Q[i]=R[j]=1;
					ret+=q[i]+r[j]+p[i][j];
					for(int k=0;k<a;k++){
						r[k]+=p[k][j];
					}
					for(int k=0;k<b;k++){
						q[k]+=p[i][k];
					}
					upd=true;
					goto wolf;
				}
			}
		}
		wolf:;
		if(!upd)break;
	}
	printf("%lld\n",ret);
}
0