結果

問題 No.519 アイドルユニット
ユーザー uafr_csuafr_cs
提出日時 2017-11-08 15:33:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,106 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 74,848 KB
実行使用メモリ 125,768 KB
最終ジャッジ日時 2023-08-15 21:13:44
合計ジャッジ時間 9,892 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
124,904 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 126 ms
55,732 KB
testcase_05 AC 129 ms
55,792 KB
testcase_06 AC 133 ms
56,072 KB
testcase_07 AC 135 ms
55,768 KB
testcase_08 AC 142 ms
56,168 KB
testcase_09 AC 145 ms
55,952 KB
testcase_10 AC 167 ms
55,828 KB
testcase_11 AC 168 ms
58,628 KB
testcase_12 AC 124 ms
56,048 KB
testcase_13 AC 167 ms
58,324 KB
testcase_14 AC 170 ms
58,124 KB
testcase_15 AC 169 ms
58,124 KB
testcase_16 AC 168 ms
57,796 KB
testcase_17 AC 173 ms
58,740 KB
testcase_18 WA -
testcase_19 AC 168 ms
58,276 KB
testcase_20 AC 169 ms
58,040 KB
testcase_21 AC 167 ms
57,812 KB
testcase_22 AC 167 ms
58,088 KB
testcase_23 AC 168 ms
58,392 KB
testcase_24 AC 180 ms
60,036 KB
testcase_25 AC 190 ms
60,252 KB
testcase_26 AC 186 ms
58,704 KB
testcase_27 AC 183 ms
60,072 KB
testcase_28 WA -
testcase_29 AC 275 ms
125,592 KB
testcase_30 AC 271 ms
125,392 KB
testcase_31 AC 278 ms
125,768 KB
testcase_32 AC 282 ms
125,136 KB
testcase_33 AC 127 ms
55,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static int solve_DP(int n, int[][] adj){
		int[] DP = new int[1 << n];
		final int INF = Integer.MAX_VALUE / 2 - 1;
		Arrays.fill(DP, INF);
		DP[0] = 0;
		
		for(int bit = 0; bit < (1 << n); bit++){
			if(DP[bit] >= INF){ continue; }
			
			int i = 0;
			for (; (bit & (1 << i)) != 0; ++i);
			
			final int fst = 1 << i;
			for(int j = i + 1; j < n; j++){
				final int snd = 1 << j;
				
				final int next_bit = bit | fst | snd;
				DP[next_bit] = Math.min(DP[next_bit], DP[bit] + adj[i][j]);
			}
		}
		
		return DP[(1 << n) - 1];
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		final int max = 1000;
		int[][] adj = new int[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				adj[i][j] = max - sc.nextInt();
			}
		}
		
		final int solve = solve_DP(n, adj);
		
		System.out.println(max * (n / 2) - solve);
	}
}
0