結果
問題 | No.43 野球の試合 |
ユーザー |
![]() |
提出日時 | 2015-06-03 20:13:11 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,002 bytes |
コンパイル時間 | 2,735 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 58,404 KB |
最終ジャッジ日時 | 2024-07-06 13:58:01 |
合計ジャッジ時間 | 4,130 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 WA * 2 |
ソースコード
import java.util.Arrays;import java.util.LinkedList;import java.util.Scanner;public class Main {public static class Team implements Comparable<Team> {int degs, id;public Team(int degs, int id) {super();this.degs = degs;this.id = id;}@Overridepublic int compareTo(Team o) {if(Integer.compare(o.degs, this.degs) != 0){return Integer.compare(o.degs, this.degs);}else{return Integer.compare(this.id, o.id);}}@Overridepublic String toString(){return this.id + " : " + this.degs;}}public static int dfs(final int N, int x, int y, Team[] teams, boolean[][] undecided){if(y == N){Team[] sorted = new Team[N];System.arraycopy(teams, 0, sorted, 0, N);Arrays.sort(sorted);for(int i = 0; i < N; i++){if(sorted[i].id == 0){return i + 1;}}return N;}else if(!undecided[y][x]){return dfs(N, (x + 1) % N, x == N - 1 ? y + 1 : y, teams, undecided);}else{int ret = Integer.MAX_VALUE;{teams[y].degs++; teams[x].degs--;ret = Math.min(ret, dfs(N, x == N - 1 ? y + 1 : x + 1, (x == N - 1) ? y + 1 : y, teams, undecided));teams[y].degs--; teams[x].degs++;}{teams[y].degs--; teams[x].degs++;ret = Math.min(ret, dfs(N, x == N - 1 ? y + 1 : x + 1, (x == N - 1) ? y + 1 : y, teams, undecided));teams[y].degs++; teams[x].degs--;}return ret;}}public static void main(String[] args){Scanner sc = new Scanner(System.in);final int N = sc.nextInt();Team[] teams = new Team[N];for(int i = 0; i < N; i++){teams[i] = new Team(0, i);}boolean[][] undecided = new boolean[N][N];for(int i = 0; i < N; i++){char[] inputs = sc.next().toCharArray();for(int j = 0; j < N; j++){if(inputs[j] == 'o'){teams[i].degs++;teams[j].degs--;}else if(inputs[j] == '-'){undecided[i][j] = true;}}}System.out.println(dfs(N, 0, 0, teams, undecided));}}