結果
問題 | No.43 野球の試合 |
ユーザー | shin |
提出日時 | 2022-06-05 15:51:00 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 231 ms / 5,000 ms |
コード長 | 1,790 bytes |
コンパイル時間 | 4,991 ms |
コンパイル使用メモリ | 79,704 KB |
実行使用メモリ | 60,444 KB |
最終ジャッジ日時 | 2024-09-21 04:11:27 |
合計ジャッジ時間 | 6,280 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
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; } }