結果

問題 No.43 野球の試合
ユーザー shinshin
提出日時 2022-06-05 15:51:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 1,790 bytes
コンパイル時間 5,297 ms
コンパイル使用メモリ 80,048 KB
実行使用メモリ 63,576 KB
最終ジャッジ日時 2023-10-21 03:12:22
合計ジャッジ時間 6,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
53,532 KB
testcase_01 AC 56 ms
53,520 KB
testcase_02 AC 56 ms
52,448 KB
testcase_03 AC 58 ms
52,416 KB
testcase_04 AC 58 ms
53,512 KB
testcase_05 AC 58 ms
53,520 KB
testcase_06 AC 63 ms
52,468 KB
testcase_07 AC 236 ms
63,576 KB
testcase_08 AC 59 ms
53,516 KB
testcase_09 AC 59 ms
52,448 KB
testcase_10 AC 59 ms
50,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class No43 {

	public static void main(String[] args) throws IOException{
		//野球の試合
		String[] str = readStr();
		int N = Integer.parseInt(str[0]);
		char[][] s = new char[N][N];
		
		for(int i = 0;i < N;i++) {
			s[i] = str[i+1].toCharArray();
		}
		
		
		int ans = Math.min(judge(Arrays.copyOf(s, N) , N) , N);
		
		System.out.println(ans);
		

	}
	
	public static int judge(char[][] s , int N) {
		int ans = N;
		char[][] c = new char[N][N];
		
		for(int i = 0;i < N;i++) {
			for(int j = 0;j < N;j++) {
				c[i][j] = s[i][j];
			}
		}
		
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				if(c[i][j] == '-') {
					c[i][j] = 'o';
					c[j][i] = 'x';
					ans = Math.min(judge(c , N) , ans);
					
					c[i][j] = 'x';
					c[j][i] = 'o';
					ans = Math.min(judge(c , N) , ans);
					return ans;
				}
			}
		}
		TreeSet<Integer> ts = new TreeSet<>();
		int my = 0;
		
		for(int i = 0;i < N;i++) {
			int count = 0;
			for(int j = 0;j < N;j++) {
				count += (c[i][j] == 'o' ? 1 : 0);
				
			}
			my += (i == 0 ? count : 0);
			ts.add(count);
		}

		Integer[] result = new Integer[ts.size()];
		ts.toArray(result);
		
		for(int i = 0;i < result.length;i++) {
			if(result[i] == my) {
				ans = result.length - i;
			}
		}
		
		return ans;
	}
	
	public static String[] readStr() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<>();

		do {
			list.add(br.readLine());
		}while(br.ready());

		br.close();

		String[] text = new String[list.size()];
		list.toArray(text);

		return text;

	}

}
0