結果
問題 | No.43 野球の試合 |
ユーザー |
|
提出日時 | 2022-06-05 15:13:55 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,616 bytes |
コンパイル時間 | 3,774 ms |
コンパイル使用メモリ | 79,476 KB |
実行使用メモリ | 50,452 KB |
最終ジャッジ日時 | 2024-09-21 04:11:09 |
合計ジャッジ時間 | 5,117 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 WA * 1 |
ソースコード
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;}}