結果
問題 | No.43 野球の試合 |
ユーザー | nanophoto12 |
提出日時 | 2014-10-28 23:56:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,170 bytes |
コンパイル時間 | 4,481 ms |
コンパイル使用メモリ | 111,980 KB |
実行使用メモリ | 26,300 KB |
最終ジャッジ日時 | 2024-06-09 17:35:51 |
合計ジャッジ時間 | 5,428 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
23,824 KB |
testcase_01 | AC | 25 ms
23,828 KB |
testcase_02 | AC | 24 ms
21,552 KB |
testcase_03 | AC | 26 ms
24,004 KB |
testcase_04 | AC | 25 ms
23,836 KB |
testcase_05 | AC | 24 ms
24,084 KB |
testcase_06 | WA | - |
testcase_07 | AC | 25 ms
24,084 KB |
testcase_08 | AC | 25 ms
23,984 KB |
testcase_09 | AC | 24 ms
25,792 KB |
testcase_10 | AC | 23 ms
21,684 KB |
コンパイルメッセージ
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); } }