結果

問題 No.1279 Array Battle
ユーザー ks2mks2m
提出日時 2020-11-06 21:25:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 2,100 ms
コンパイル使用メモリ 86,540 KB
実行使用メモリ 65,720 KB
最終ジャッジ日時 2023-09-29 18:05:45
合計ジャッジ時間 7,418 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,316 KB
testcase_01 AC 119 ms
55,884 KB
testcase_02 AC 126 ms
56,672 KB
testcase_03 AC 120 ms
56,560 KB
testcase_04 AC 118 ms
56,640 KB
testcase_05 AC 117 ms
55,876 KB
testcase_06 AC 118 ms
56,156 KB
testcase_07 AC 117 ms
56,296 KB
testcase_08 AC 118 ms
55,772 KB
testcase_09 AC 120 ms
56,200 KB
testcase_10 AC 130 ms
56,444 KB
testcase_11 AC 133 ms
56,056 KB
testcase_12 AC 171 ms
58,424 KB
testcase_13 AC 271 ms
63,828 KB
testcase_14 AC 263 ms
64,260 KB
testcase_15 AC 402 ms
63,628 KB
testcase_16 AC 412 ms
65,720 KB
testcase_17 AC 428 ms
63,900 KB
testcase_18 AC 452 ms
63,944 KB
testcase_19 AC 434 ms
63,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	static int n;
	static int[] a, b;
	static TreeMap<Integer, Integer> map;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
		}
		sc.close();

		map = new TreeMap<>();
		permutation(new LinkedHashSet<Integer>());
		System.out.println(map.lastEntry().getValue());
	}

	static void permutation(LinkedHashSet<Integer> set) {
		if (set.size() == n) {
			int sum = 0;
			int j = 0;
			for (int i : set) {
				int val = Math.max(a[i] - b[j], 0);
				sum += val;
				j++;
			}
			map.put(sum, map.getOrDefault(sum, 0) + 1);
			return;
		}

		for (int i = 0; i < n; i++) {
			if (!set.contains(i)) {
				set.add(i);
				permutation(set);
				set.remove(i);
			}
		}
	}
}
0