結果
| 問題 |
No.43 野球の試合
|
| コンテスト | |
| ユーザー |
neko_the_shadow
|
| 提出日時 | 2019-02-24 16:51:57 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 621 ms / 5,000 ms |
| コード長 | 2,721 bytes |
| コンパイル時間 | 4,346 ms |
| コンパイル使用メモリ | 90,220 KB |
| 実行使用メモリ | 61,164 KB |
| 最終ジャッジ日時 | 2024-12-23 06:24:10 |
| 合計ジャッジ時間 | 7,466 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.OptionalInt;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int n = Integer.parseInt(stdin.nextLine());
char[] s = new char[n * n];
for (int i = 0; i < n; i++) {
String t = stdin.nextLine();
for (int j = 0; j < n; j++) s[i * n + j] = t.charAt(j);
}
List<Integer> games = new ArrayList<>();
for (int i = 0; i < n * n; i++) {
int x = i / n;
int y = i % n;
if (x < y && s[i] == '-') games.add(i);
}
int ans = Integer.MAX_VALUE;
for (int bit = 0, len = games.size(); bit < (1 << len); bit++) {
for (int i = 0; i < len; i++) {
int x = games.get(i) / n;
int y = games.get(i) % n;
if ((bit & (1 << i)) == 0) {
s[n * x + y] = 'o';
s[n * y + x] = 'x';
} else {
s[n * x + y] = 'x';
s[n * y + x] = 'o';
}
}
int[] counter = new int[n];
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
if (x >= y) continue;
if (s[n * x + y] == 'o') {
counter[x]++;
} else {
counter[y]++;
}
}
}
List<List<Integer>> standings = IntStream.range(0, n)
.boxed()
.collect(Collectors.groupingBy(i -> counter[i]))
.entrySet()
.stream()
.sorted(Comparator.comparing(Entry::getKey, Comparator.reverseOrder()))
.map(Entry::getValue)
.collect(Collectors.toList());
OptionalInt rank = IntStream.range(0, n)
.filter(i -> standings.get(i).contains(0))
.findFirst();
if (rank.isPresent()) ans = Math.min(ans, rank.getAsInt() + 1);
}
System.out.println(ans);
}
}
neko_the_shadow