結果
問題 | No.43 野球の試合 |
ユーザー |
![]() |
提出日時 | 2014-10-29 23:28:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,317 bytes |
コンパイル時間 | 1,288 ms |
コンパイル使用メモリ | 112,152 KB |
実行使用メモリ | 25,912 KB |
最終ジャッジ日時 | 2024-12-30 13:46:03 |
合計ジャッジ時間 | 2,384 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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];}}var max = Dfs(grid, 0, 0, n);Console.WriteLine(max.ToString(CultureInfo.InvariantCulture));}private static int Dfs(char[,] grid, int x, int y, int n){if (y == n ){var winCounts = new int[n];for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){if (grid[j, i] == 'o'){winCounts[j]++;}}}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 == n){return Dfs(grid, 0, y + 1, n);}if (grid[y, x] != '-'){return Dfs(grid, x + 1, y, n);}grid[y, x] = 'o';grid[x, y] = 'x';int first = Dfs(grid, x + 1, y, n);grid[y, x] = 'x';grid[x, y] = 'o';int second = Dfs(grid, x + 1, y, n);grid[y, x] = '-';grid[x, y] = '-';return Math.Min(first, second);}}