結果

問題 No.43 野球の試合
ユーザー tsunabittsunabit
提出日時 2019-09-09 11:10:12
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,341 bytes
コンパイル時間 3,251 ms
コンパイル使用メモリ 74,588 KB
実行使用メモリ 60,716 KB
最終ジャッジ日時 2023-09-10 19:56:00
合計ジャッジ時間 11,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
53,704 KB
testcase_01 AC 116 ms
55,888 KB
testcase_02 AC 118 ms
55,888 KB
testcase_03 AC 119 ms
55,924 KB
testcase_04 AC 116 ms
55,684 KB
testcase_05 AC 117 ms
55,876 KB
testcase_06 AC 179 ms
60,716 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
				}
			}
		}
		
		int[] kati = new int[n];
//		int count = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if("o".equals(map1[i][j])) kati[i]++;
			}
//			kati[i] = count;
//			count = 0;
		}
		
		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