結果

問題 No.43 野球の試合
ユーザー 37zigen37zigen
提出日時 2020-03-22 00:06:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 1,121 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 74,996 KB
実行使用メモリ 58,880 KB
最終ジャッジ日時 2023-08-25 17:26:09
合計ジャッジ時間 4,658 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
54,544 KB
testcase_01 AC 117 ms
56,308 KB
testcase_02 AC 116 ms
56,000 KB
testcase_03 AC 122 ms
55,904 KB
testcase_04 AC 127 ms
55,944 KB
testcase_05 AC 123 ms
56,200 KB
testcase_06 AC 164 ms
58,692 KB
testcase_07 AC 152 ms
58,708 KB
testcase_08 AC 151 ms
58,808 KB
testcase_09 AC 156 ms
58,716 KB
testcase_10 AC 158 ms
58,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		char[][] m=new char[N][N];
		for(int i=0;i<N;++i)m[i]=sc.next().toCharArray();
		int ans=Integer.MAX_VALUE/3;
		for(int s=0;s<1L<<(N*(N-1)/2);++s) {
			int[] a=new int[N];
			int pos=0;
			for(int i=0;i<N;++i) {
				for(int j=i+1;j<N;++j) {
					if(m[i][j]=='-') {
						if((s>>pos)%2==1) {
							a[i]++;
						}else {
							a[j]++;
						}
					}else if(m[i][j]=='o'){
						++a[i];
					}else {
						++a[j];
					}
					++pos;
				}
			}
			int get=a[0];
			Arrays.sort(a);
			int cur=a.length-1;
			int tmp=1;
			while(a[cur]!=get) {
				--cur;
				if(a[cur]!=a[cur+1])++tmp;
			}
			ans=Math.min(ans, tmp);
		}
		System.out.println(ans);
	}


	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0