結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー 37zigen37zigen
提出日時 2019-12-12 22:08:43
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,150 ms / 2,500 ms
コード長 1,285 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 75,304 KB
実行使用メモリ 83,464 KB
最終ジャッジ日時 2023-09-08 01:19:14
合計ジャッジ時間 22,376 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,312 KB
testcase_01 AC 122 ms
56,128 KB
testcase_02 AC 122 ms
56,084 KB
testcase_03 AC 124 ms
56,068 KB
testcase_04 AC 132 ms
55,712 KB
testcase_05 AC 148 ms
55,980 KB
testcase_06 AC 142 ms
55,880 KB
testcase_07 AC 176 ms
56,220 KB
testcase_08 AC 200 ms
58,572 KB
testcase_09 AC 190 ms
56,520 KB
testcase_10 AC 186 ms
54,708 KB
testcase_11 AC 863 ms
75,028 KB
testcase_12 AC 900 ms
74,464 KB
testcase_13 AC 740 ms
73,872 KB
testcase_14 AC 378 ms
60,108 KB
testcase_15 AC 614 ms
69,416 KB
testcase_16 AC 1,009 ms
71,796 KB
testcase_17 AC 456 ms
60,592 KB
testcase_18 AC 1,142 ms
71,820 KB
testcase_19 AC 730 ms
74,964 KB
testcase_20 AC 407 ms
62,428 KB
testcase_21 AC 310 ms
59,348 KB
testcase_22 AC 385 ms
60,844 KB
testcase_23 AC 220 ms
58,684 KB
testcase_24 AC 727 ms
69,080 KB
testcase_25 AC 1,052 ms
80,820 KB
testcase_26 AC 1,150 ms
71,776 KB
testcase_27 AC 1,101 ms
71,720 KB
testcase_28 AC 1,119 ms
83,020 KB
testcase_29 AC 932 ms
80,884 KB
testcase_30 AC 773 ms
80,848 KB
testcase_31 AC 694 ms
83,464 KB
testcase_32 AC 1,026 ms
80,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
	 	Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long[] A=new long[N+1];
		long[] B=new long[N+1];
		long[] D=new long[N];
		for(int i=0;i<=N;++i){
			A[i]=sc.nextLong();
		}
		for(int i=0;i<=N;++i){
			B[i]=sc.nextLong();
		}
		for(int i=0;i<N;++i){
			D[i]=sc.nextLong();
		}
		Arrays.sort(D);
		int ok=0;
		int ng=N+1;
		while(ng-ok>1){
			int middle=(ok+ng)/2;
			if(check(A,B,D,middle)){
				ok=middle;
			}else{
				ng=middle;
			}
		}
		System.out.println(ok);
	}
	
	boolean check(long[] A, long[] B, long[] D, int curn){
		int N=D.length;
		boolean[][] dp=new boolean[N+1][N+1];
		for(int i=0;i<dp.length;++i)
			for(int j=0;j<dp[i].length;++j)
				dp[i][j]=false;
		dp[0][0]=true;
		for(int i=1;i<=curn;++i){
			for(int a=0;a<=N;++a){
				int b=i-a;
				if(b<0||b>N)continue;
				if(D[curn-i]<=A[a]+B[b]){
					if(a>0) dp[i][a]|=dp[i-1][a-1];
					if(b>0) dp[i][a]|=dp[i-1][a];
				}
			}
		}
		int ans=0;
		for(int i=0;i<=N;++i){
			for(int j=0;j<=N;++j){
				if(dp[i][j]) ans=Math.max(ans,i);
			}
		}
		return ans>=curn;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0