結果

問題 No.43 野球の試合
ユーザー shinshin
提出日時 2022-06-05 15:13:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 6,083 ms
コンパイル使用メモリ 78,984 KB
実行使用メモリ 53,432 KB
最終ジャッジ日時 2023-10-21 03:12:03
合計ジャッジ時間 7,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
52,500 KB
testcase_01 AC 58 ms
52,296 KB
testcase_02 AC 57 ms
51,528 KB
testcase_03 AC 56 ms
53,424 KB
testcase_04 WA -
testcase_05 AC 57 ms
53,432 KB
testcase_06 AC 57 ms
52,488 KB
testcase_07 AC 57 ms
52,460 KB
testcase_08 AC 56 ms
53,420 KB
testcase_09 AC 57 ms
52,316 KB
testcase_10 AC 57 ms
53,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
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(s , N) , N);
		
		System.out.println(ans);
		

	}
	
	public static int judge(char[][] s , int N) {
		int ans = N;
		
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				if(s[i][j] == '-') {
					s[i][j] = 'o';
					s[j][i] = 'x';
					ans = Math.min(judge(s , N) , ans);
					s[i][j] = 'x';
					s[j][i] = 'o';
					ans = Math.min(judge(s , 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 += (s[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