結果
問題 | No.1279 Array Battle |
ユーザー |
![]() |
提出日時 | 2020-11-06 21:25:34 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 462 ms / 2,000 ms |
コード長 | 989 bytes |
コンパイル時間 | 2,415 ms |
コンパイル使用メモリ | 79,628 KB |
実行使用メモリ | 62,672 KB |
最終ジャッジ日時 | 2024-07-22 12:05:01 |
合計ジャッジ時間 | 7,830 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
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); } } } }