結果

問題 No.519 アイドルユニット
ユーザー uafr_csuafr_cs
提出日時 2017-11-08 15:37:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 249 ms / 1,000 ms
コード長 1,148 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 79,096 KB
実行使用メモリ 125,624 KB
最終ジャッジ日時 2023-08-15 21:14:29
合計ジャッジ時間 9,081 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
125,416 KB
testcase_01 AC 241 ms
125,592 KB
testcase_02 AC 182 ms
75,492 KB
testcase_03 AC 147 ms
58,356 KB
testcase_04 AC 108 ms
56,220 KB
testcase_05 AC 109 ms
56,152 KB
testcase_06 AC 119 ms
56,004 KB
testcase_07 AC 118 ms
56,220 KB
testcase_08 AC 129 ms
56,352 KB
testcase_09 AC 128 ms
56,132 KB
testcase_10 AC 128 ms
55,852 KB
testcase_11 AC 146 ms
59,948 KB
testcase_12 AC 111 ms
56,368 KB
testcase_13 AC 156 ms
57,860 KB
testcase_14 AC 150 ms
58,272 KB
testcase_15 AC 153 ms
57,664 KB
testcase_16 AC 143 ms
58,208 KB
testcase_17 AC 147 ms
57,712 KB
testcase_18 AC 145 ms
58,220 KB
testcase_19 AC 150 ms
58,044 KB
testcase_20 AC 144 ms
58,360 KB
testcase_21 AC 147 ms
57,764 KB
testcase_22 AC 146 ms
58,704 KB
testcase_23 AC 139 ms
58,508 KB
testcase_24 AC 165 ms
60,228 KB
testcase_25 AC 187 ms
60,128 KB
testcase_26 AC 192 ms
60,620 KB
testcase_27 AC 183 ms
60,064 KB
testcase_28 AC 188 ms
59,768 KB
testcase_29 AC 229 ms
125,308 KB
testcase_30 AC 249 ms
125,624 KB
testcase_31 AC 240 ms
125,508 KB
testcase_32 AC 234 ms
124,836 KB
testcase_33 AC 111 ms
56,008 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++){
				if((bit & (1 << j)) != 0){ continue; }
				
				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