結果

問題 No.519 アイドルユニット
ユーザー yuya178yuya178
提出日時 2017-06-16 00:30:13
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,951 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 77,876 KB
実行使用メモリ 68,568 KB
最終ジャッジ日時 2023-10-25 08:00:10
合計ジャッジ時間 7,448 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int arr[][] = new int[N+1][N+1];
            int ans;
            
            for(int i=1; i<=N; i++){
                for(int j=1; j<=N; j++){
                    arr[i][j] = in.nextInt();
                }
            }

            int num[] = new int[N+1];
            for(int i=1; i<=N; i++){
                num[i] = i;
            }

            ans = pair(num,arr,N);

            out.println(ans);

        }

        private static int pair(int num[], int arr[][],int N){
            int res=0;
            int max=0;
            int start=1;
            int copy[] = new int[N+1];

            Arrays.sort(num);
            if(num[N]==0) return 0;
            for(int i=1; i<=N; i++){
                if(num[i]!=0){
                    start=i;
                    break;
                }
            }

            for(int i=1; start+i<=N; i++){
                for(int j=1; j<=N; j++){
                copy[j] = num[j];
            }
                copy[start]=0;
                copy[start+i]=0;
                res = arr[num[start]][num[start+i]]+pair(copy,arr,N);
                if(res>max){
                    max=res;
                }
            }
            return max;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
0