結果

問題 No.43 野球の試合
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-24 13:13:54
言語 Java19
(openjdk 21)
結果
AC  
実行時間 228 ms / 5,000 ms
コード長 2,090 bytes
コンパイル時間 2,692 ms
コンパイル使用メモリ 79,656 KB
実行使用メモリ 59,712 KB
最終ジャッジ日時 2023-09-18 08:52:24
合計ジャッジ時間 4,483 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,136 KB
testcase_01 AC 126 ms
56,076 KB
testcase_02 AC 127 ms
55,984 KB
testcase_03 AC 132 ms
55,628 KB
testcase_04 AC 130 ms
56,096 KB
testcase_05 AC 129 ms
55,900 KB
testcase_06 AC 138 ms
58,036 KB
testcase_07 AC 228 ms
59,712 KB
testcase_08 AC 127 ms
56,260 KB
testcase_09 AC 126 ms
56,264 KB
testcase_10 AC 129 ms
56,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n = koko.nextInt();
        boolean[][] d = new boolean[n][n];
        String[] s = new String[n];
        int[] game = new int[n];
        int[] win = new int[n];
        int tgame=0;
        for(int i=0; i<n; i++){
            s[i]=koko.next();
            for(int j=0; j<n; j++){
                if(s[i].charAt(j)=='o'){
                    d[i][j]=true;
                    win[i]++;
                    game[i]++;
                }else if(s[i].charAt(j)=='-'){
                    
                }else{
                    d[i][j]=true;
                    game[i]++;
                }
            }
            tgame=tgame+game[i];
        }
        int rest = (n*n-tgame)/2;
        int ume = (int)Math.pow(2,rest);
        int[] rank = new int[ume];
        int[] twin =new int[n];
        for(int i=0; i<ume; i++){
            for(int j=0; j<n; j++){
                twin[j]=win[j];
            }
            String ni = Integer.toBinaryString(i);
            while(ni.length()<rest){
                ni="0"+ni;
            }
            int ptr=0;
            for(int j=1; j<n; j++){
                for(int k=0; k<j; k++){
                    if(!d[j][k]){
                        if(ni.charAt(ptr++)=='0'){
                            twin[k]++;
                        }else{
                            twin[j]++;
                        }
                    }
                }
            }
            int a = twin[0];
            Arrays.sort(twin);
            int prank=1;
            if(twin[n-1]==a){
                rank[i]=1;
            }else{
                for(int j=1; j<n; j++){
                    if(twin[n-j]!=twin[n-j-1]){
                        prank++;
                    }
                    if(twin[n-j-1]==a){
                        rank[i]=prank;
                    }
                }
            }
        }
        Arrays.sort(rank);
        System.out.println(rank[0]);
    }
}
0