結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー ks2mks2m
提出日時 2019-12-12 01:06:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 325 ms / 2,500 ms
コード長 1,474 bytes
コンパイル時間 4,431 ms
コンパイル使用メモリ 73,732 KB
実行使用メモリ 131,108 KB
最終ジャッジ日時 2023-09-06 13:40:32
合計ジャッジ時間 10,679 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,324 KB
testcase_01 AC 43 ms
49,336 KB
testcase_02 AC 42 ms
47,380 KB
testcase_03 AC 42 ms
47,492 KB
testcase_04 AC 42 ms
49,516 KB
testcase_05 AC 44 ms
49,348 KB
testcase_06 AC 45 ms
47,692 KB
testcase_07 AC 49 ms
49,236 KB
testcase_08 AC 66 ms
50,488 KB
testcase_09 AC 51 ms
49,352 KB
testcase_10 AC 57 ms
51,364 KB
testcase_11 AC 249 ms
112,260 KB
testcase_12 AC 245 ms
112,488 KB
testcase_13 AC 234 ms
112,544 KB
testcase_14 AC 106 ms
56,764 KB
testcase_15 AC 196 ms
84,876 KB
testcase_16 AC 271 ms
131,108 KB
testcase_17 AC 118 ms
61,260 KB
testcase_18 AC 317 ms
125,720 KB
testcase_19 AC 218 ms
112,576 KB
testcase_20 AC 119 ms
61,468 KB
testcase_21 AC 94 ms
57,012 KB
testcase_22 AC 117 ms
61,368 KB
testcase_23 AC 91 ms
52,092 KB
testcase_24 AC 215 ms
89,304 KB
testcase_25 AC 317 ms
127,044 KB
testcase_26 AC 296 ms
127,288 KB
testcase_27 AC 282 ms
129,368 KB
testcase_28 AC 325 ms
127,532 KB
testcase_29 AC 279 ms
127,464 KB
testcase_30 AC 270 ms
127,820 KB
testcase_31 AC 275 ms
127,460 KB
testcase_32 AC 285 ms
129,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n + 1];
		int[] b = new int[n + 1];
		int[] d = new int[n + 1];
		String[] sa = br.readLine().split(" ");
		for (int i = 0; i <= n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		for (int i = 0; i <= n; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		d[0] = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			d[i + 1] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.sort(d);
		int[][] c = new int[n + 2][n + 2];
		for (int i = 0; i <= n; i++) {
			int idx = n;
			for (int j = 0; j <= n; j++) {
				int sum = a[i] + b[j];
				while (sum < d[idx]) {
					idx--;
				}
				c[i][j] = idx;
			}
		}

		int[][] dp = new int[n + 2][n + 2];
		dp[0][0] = n + 1;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				dp[i + 1][j] = Math.min(c[i + 1][j], dp[i][j] - 1);
				int val = Math.min(c[i][j + 1], dp[i][j] - 1);
				dp[i][j + 1] = Math.max(dp[i][j + 1], val);
			}
		}
		dp[0][0] = 0;

		int ans = 0;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				if (dp[i][j] > 0) {
					ans = Math.max(ans, i + j);
				}
			}
		}
		System.out.println(ans);
	}
}
0