結果

問題 No.519 アイドルユニット
ユーザー uafr_csuafr_cs
提出日時 2017-11-08 15:29:41
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,080 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 78,928 KB
実行使用メモリ 122,428 KB
最終ジャッジ日時 2024-05-03 07:47:09
合計ジャッジ時間 15,290 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 121 ms
54,064 KB
testcase_05 AC 127 ms
54,080 KB
testcase_06 AC 132 ms
54,072 KB
testcase_07 AC 127 ms
54,412 KB
testcase_08 AC 129 ms
54,096 KB
testcase_09 AC 143 ms
54,412 KB
testcase_10 AC 142 ms
53,756 KB
testcase_11 AC 163 ms
56,472 KB
testcase_12 AC 102 ms
53,076 KB
testcase_13 AC 178 ms
56,076 KB
testcase_14 AC 161 ms
56,280 KB
testcase_15 AC 177 ms
56,380 KB
testcase_16 AC 163 ms
56,564 KB
testcase_17 AC 185 ms
56,484 KB
testcase_18 WA -
testcase_19 AC 160 ms
56,500 KB
testcase_20 AC 163 ms
56,320 KB
testcase_21 AC 167 ms
56,124 KB
testcase_22 AC 172 ms
56,500 KB
testcase_23 AC 162 ms
56,456 KB
testcase_24 AC 204 ms
58,544 KB
testcase_25 AC 233 ms
58,492 KB
testcase_26 AC 222 ms
58,536 KB
testcase_27 AC 218 ms
58,788 KB
testcase_28 WA -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 AC 106 ms
53,012 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];
		Arrays.fill(DP, Integer.MAX_VALUE / 2 - 1);
		DP[0] = 0;
		
		for(int bit = 0; bit < (1 << n); bit++){
			if(DP[bit] < 0){ 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