結果
問題 | No.43 野球の試合 |
ユーザー | nanophoto12 |
提出日時 | 2014-10-29 00:30:01 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,226 bytes |
コンパイル時間 | 941 ms |
コンパイル使用メモリ | 114,388 KB |
実行使用メモリ | 26,188 KB |
最終ジャッジ日時 | 2024-06-09 17:38:32 |
合計ジャッジ時間 | 1,885 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
26,188 KB |
testcase_01 | AC | 22 ms
23,984 KB |
testcase_02 | AC | 23 ms
26,184 KB |
testcase_03 | AC | 22 ms
26,184 KB |
testcase_04 | AC | 22 ms
23,764 KB |
testcase_05 | AC | 24 ms
26,052 KB |
testcase_06 | WA | - |
testcase_07 | AC | 25 ms
24,148 KB |
testcase_08 | AC | 25 ms
24,012 KB |
testcase_09 | AC | 24 ms
23,960 KB |
testcase_10 | AC | 26 ms
22,072 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]--; grid[y, x] = '-'; grid[x, y] = '-'; return Math.Min(first, second); } }