結果

問題 No.1792 科学の甲子園
ユーザー tentententen
提出日時 2023-07-20 09:23:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 159 ms / 4,000 ms
コード長 3,195 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 84,096 KB
実行使用メモリ 42,908 KB
最終ジャッジ日時 2024-05-05 01:35:54
合計ジャッジ時間 5,663 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
37,072 KB
testcase_01 AC 50 ms
36,880 KB
testcase_02 AC 47 ms
37,196 KB
testcase_03 AC 49 ms
37,332 KB
testcase_04 AC 48 ms
37,328 KB
testcase_05 AC 46 ms
36,992 KB
testcase_06 AC 51 ms
37,176 KB
testcase_07 AC 49 ms
37,168 KB
testcase_08 AC 56 ms
37,208 KB
testcase_09 AC 62 ms
37,376 KB
testcase_10 AC 50 ms
36,728 KB
testcase_11 AC 123 ms
41,988 KB
testcase_12 AC 117 ms
41,084 KB
testcase_13 AC 124 ms
41,704 KB
testcase_14 AC 159 ms
42,908 KB
testcase_15 AC 121 ms
41,120 KB
testcase_16 AC 50 ms
37,044 KB
testcase_17 AC 48 ms
36,752 KB
testcase_18 AC 51 ms
37,116 KB
testcase_19 AC 113 ms
41,040 KB
testcase_20 AC 144 ms
42,712 KB
testcase_21 AC 103 ms
40,832 KB
testcase_22 AC 126 ms
41,856 KB
testcase_23 AC 112 ms
41,252 KB
testcase_24 AC 46 ms
36,640 KB
testcase_25 AC 53 ms
37,308 KB
testcase_26 AC 50 ms
37,000 KB
testcase_27 AC 145 ms
41,884 KB
testcase_28 AC 142 ms
42,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static Student[] students;
    static long[][][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        students = new Student[n];
        for (int i = 0; i < n; i++) {
            int[] tmp = new int[6];
            for (int j = 0; j < 6; j++) {
                tmp[j] = sc.nextInt();
            }
            students[i] = new Student(tmp);
        }
        dp = new long[n][4][1 << 6];
        for (long[][] arr : dp) {
            for (long[] arr2 : arr) {
                Arrays.fill(arr2, -1);
            }
        }
        System.out.println(dfw(n - 1, 3, (1 << 6) - 1));
    }
    
    static long dfw(int idx, int w, int v) {
        if (v == 0) {
            return 1;
        }
        if (idx < 0 || w < 0) {
            return 0;
        }
        if (dp[idx][w][v] < 0) {
            dp[idx][w][v] = dfw(idx - 1, w, v);
            for (int i = v; i > 0; i = ((i - 1) & v)) {
                if ((i & v) != i) {
                    continue;
                }
                dp[idx][w][v] = Math.max(dp[idx][w][v], students[idx].points[i] * dfw(idx - 1, w - 1, v ^ i));
            }
        }
        return dp[idx][w][v];
    }
    
    static class Student {
        int[] values;
        long[] points;
        
        public Student(int[] values) {
            this.values = values;
            init();
        }
        
        private void init() {
            points = new long[1 << 6];
            points[0] = 1;
            for (int i = 1; i < (1 << 6); i++) {
                for (int j = 0; j < 6; j++) {
                    if ((i & (1 << j)) == 0) {
                        continue;
                    }
                    points[i] = points[i ^ (1 << j)] * values[j];
                    break;
                }
            }
        }
        
    }
    
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0