結果

問題 No.519 アイドルユニット
ユーザー uafr_csuafr_cs
提出日時 2017-11-08 15:33:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,106 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 78,308 KB
実行使用メモリ 123,536 KB
最終ジャッジ日時 2024-05-03 07:47:30
合計ジャッジ時間 8,743 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
122,132 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 121 ms
53,848 KB
testcase_05 AC 122 ms
54,004 KB
testcase_06 AC 131 ms
54,072 KB
testcase_07 AC 131 ms
54,112 KB
testcase_08 AC 127 ms
54,316 KB
testcase_09 AC 127 ms
54,072 KB
testcase_10 AC 154 ms
54,320 KB
testcase_11 AC 165 ms
56,708 KB
testcase_12 AC 109 ms
52,960 KB
testcase_13 AC 156 ms
56,180 KB
testcase_14 AC 155 ms
56,336 KB
testcase_15 AC 147 ms
56,552 KB
testcase_16 AC 151 ms
56,280 KB
testcase_17 AC 154 ms
56,460 KB
testcase_18 WA -
testcase_19 AC 154 ms
56,304 KB
testcase_20 AC 153 ms
56,260 KB
testcase_21 AC 145 ms
56,108 KB
testcase_22 AC 159 ms
56,152 KB
testcase_23 AC 165 ms
56,188 KB
testcase_24 AC 168 ms
58,436 KB
testcase_25 AC 192 ms
58,444 KB
testcase_26 AC 166 ms
58,660 KB
testcase_27 AC 184 ms
58,688 KB
testcase_28 WA -
testcase_29 AC 266 ms
123,536 KB
testcase_30 AC 253 ms
122,124 KB
testcase_31 AC 243 ms
121,896 KB
testcase_32 AC 250 ms
122,068 KB
testcase_33 AC 113 ms
54,020 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