結果

問題 No.43 野球の試合
ユーザー GrenacheGrenache
提出日時 2015-11-03 18:53:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 232 ms / 5,000 ms
コード長 1,571 bytes
コンパイル時間 3,529 ms
コンパイル使用メモリ 80,012 KB
実行使用メモリ 58,848 KB
最終ジャッジ日時 2023-10-11 13:27:03
合計ジャッジ時間 6,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,308 KB
testcase_01 AC 126 ms
56,136 KB
testcase_02 AC 125 ms
56,032 KB
testcase_03 AC 126 ms
56,084 KB
testcase_04 AC 149 ms
56,640 KB
testcase_05 AC 150 ms
56,756 KB
testcase_06 AC 165 ms
58,524 KB
testcase_07 AC 232 ms
58,324 KB
testcase_08 AC 156 ms
58,848 KB
testcase_09 AC 141 ms
57,980 KB
testcase_10 AC 152 ms
58,512 KB
権限があれば一括ダウンロードができます

ソースコード

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();
        }

        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]++;
				}
			}
		}

    	for (int j = 0; j < n; 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) {
    				return Integer.MAX_VALUE;
    			} else if (s[j][k] == 'o' && !win) {
    				return Integer.MAX_VALUE;
    			} else if (s[j][k] == '-' && win) {
    				cnt[j]++;
    			} else if (s[j][k] == '-' && !win) {
    				cnt[k]++;
    			}
    		}
    	}
		
		int cnt0 = cnt[0];
		Arrays.sort(cnt);

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

		return ret;
	}
}
0