結果

問題 No.43 野球の試合
ユーザー GrenacheGrenache
提出日時 2015-11-03 18:08:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,517 bytes
コンパイル時間 4,784 ms
コンパイル使用メモリ 75,140 KB
実行使用メモリ 58,544 KB
最終ジャッジ日時 2023-10-11 13:26:17
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,552 KB
testcase_01 AC 125 ms
55,852 KB
testcase_02 AC 125 ms
55,940 KB
testcase_03 AC 126 ms
55,968 KB
testcase_04 AC 142 ms
55,880 KB
testcase_05 AC 138 ms
56,040 KB
testcase_06 WA -
testcase_07 AC 167 ms
58,232 KB
testcase_08 WA -
testcase_09 AC 158 ms
58,456 KB
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;


public class Main_yukicoder43 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        char[][] s = new char[n][];
        for (int i = 0; i < n; i++) {
        	s[i] = sc.next().toCharArray();
        }

        for (int i = 0; i < n; i++) {
        	if (s[0][i] == '-') {
        		s[0][i] = 'o';
        		s[i][0] = 'x';
        	}
        }
        
        int m = n * (n - 1) / 2;

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < 0x1 << m; i++) {
        	min = Math.min(min, getMin(s, i));
        }
        
        System.out.println(min);

        sc.close();
    }

	private static int getMin(char[][] s, int i) {
		int n = s[0].length;
		
		int[] cnt = new int[n];
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (j == k) {
					continue;
				}
				if (s[j][k] == 'o') {
					cnt[j]++;
				}
			}
		}

		out:
    	for (int j = 1; j < n; j++) {
			int cnttmp = cnt[j];
    		for (int k = j + 1; k < n; k++) {
    			int tmp = (n - 1 - j) * (n - 1 - j - 1) / 2 + n - 1 - k;
    			boolean win = (i & 0x1 << tmp) != 0;
    			if (s[j][k] == 'x' && win) {
    				continue out;
    			} else if (s[j][k] == '-' && win) {
    				cnttmp++;
    			}
    		}
    		cnt[j] = cnttmp;
    	}
		
		int cnt0 = cnt[0];
		Arrays.sort(cnt);

		int j;
		for (j = n - 1; j >= 0; j--) {
			if (cnt[j] <= cnt0) {
				break;
			}
		}

		return n - j;
	}
}
0