結果

問題 No.43 野球の試合
ユーザー tsunabittsunabit
提出日時 2019-09-09 11:12:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 386 ms / 5,000 ms
コード長 1,291 bytes
コンパイル時間 5,232 ms
コンパイル使用メモリ 74,296 KB
実行使用メモリ 63,740 KB
最終ジャッジ日時 2023-09-10 19:59:23
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,872 KB
testcase_01 AC 126 ms
55,588 KB
testcase_02 AC 125 ms
55,612 KB
testcase_03 AC 126 ms
55,752 KB
testcase_04 AC 127 ms
55,816 KB
testcase_05 AC 125 ms
55,392 KB
testcase_06 AC 131 ms
55,564 KB
testcase_07 AC 386 ms
63,740 KB
testcase_08 AC 129 ms
55,556 KB
testcase_09 AC 129 ms
55,592 KB
testcase_10 AC 127 ms
57,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No43 {
	public static int ans = 99;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String[][] s = new String[n][n];
		for(int i = 0; i < n; i++) {
			s[i] = sc.nextLine().split("");
		}
		dfs(s, n);
		System.out.println(ans); 
	}
	
	public static void dfs(String[][] s, int n) {
		String[][] map1 = copy(s);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if("-".equals(map1[i][j])) {
					map1[i][j] = "o";
					map1[j][i] = "x";
					dfs(map1, n);
					map1[i][j] = "x";
					map1[j][i] = "o";
					dfs(map1, n);
					return;
				}
			}
		}
		
		int[] kati = new int[n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if("o".equals(map1[i][j])) kati[i]++;
			}
		}
		
		int temp = kati[0];
		int r = 1;
		int ima = 99;
		Arrays.sort(kati);
		for(int i = n-1; i >= 0; i--) {
			if(temp < kati[i] && ima > kati[i]) {
				r++;
				ima = kati[i];
			}
		}
		if(ans > r) {
			ans = r;
		}
	}
	
	static String[][] copy(String[][] from){
		int aa = from[0].length;
		String[][] to = new String[aa][aa];
		for(int i=0;i<aa;i++){
			for(int j=0;j<aa;j++){
				to[i][j]=from[i][j];
			}
		}
		return to;
	}
}
0