結果
問題 |
No.43 野球の試合
|
ユーザー |
![]() |
提出日時 | 2014-10-28 23:56:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,170 bytes |
コンパイル時間 | 4,287 ms |
コンパイル使用メモリ | 106,752 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-12-30 13:22:58 |
合計ジャッジ時間 | 5,298 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 WA * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Globalization; class Program { public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); string[] texts = new string[n]; for (int i = 0; i < n; i++) { texts[i] = Console.ReadLine(); } char[,] grid = new char[n,n]; for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { grid[i, k] = texts[i][k]; } } int[] winCounts = new int[n]; for (int i = 1; i < n; i++) { if (grid[0,i] == 'o') { winCounts[0]++; } else if (grid[0,i] == '-') { winCounts[0]++; grid[0, i] = 'o'; grid[i, 0] = 'x'; } } for (int y = 1; y < n; y++) { for (int x = 0; x < n; x++) { if (grid[y, x] == 'o') { winCounts[y]++; } } } var max = Dfs(grid, 0, 1, winCounts, n); Console.WriteLine(max.ToString(CultureInfo.InvariantCulture)); } private static int Dfs(char[,] grid, int x, int y, int[] winCounts, int n) { if (x == n - 1 && y == n - 1) { var values = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { values[i] = new Tuple<int, int>(i, winCounts[i]); } Array.Sort(values, (tuple, tuple1) => tuple1.Item2.CompareTo(tuple.Item1)); int rank = 0; int previous = int.MaxValue; for (int i = 0; i < n; i++) { if (previous > values[i].Item2) { rank++; } if (values[i].Item1 == 0) { return rank; } previous = values[i].Item2; } throw new Exception(); } if (x == y) { return Dfs(grid, x + 1, y, winCounts, n); } if (grid[y, x] != '-') { if (x == n - 1) { return Dfs(grid, 0, y + 1, winCounts, n); } return Dfs(grid, x + 1, y, winCounts, n); } int first = 0; winCounts[y]++; grid[y, x] = 'o'; grid[x, y] = 'x'; if (x == n - 1) { first = Dfs(grid, 0, y + 1, winCounts, n); } else { first = Dfs(grid, x + 1, y, winCounts, n); } winCounts[y]--; winCounts[x]++; grid[y, x] = 'x'; grid[x, y] = 'o'; var second = 0; if (x == n - 1) { second = Dfs(grid, 0, y + 1, winCounts, n); } else { second = Dfs(grid, x + 1, y, winCounts, n); } winCounts[x]--; return Math.Min(first, second); } }