結果
| 問題 |
No.43 野球の試合
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2014-10-29 00:10:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,226 bytes |
| コンパイル時間 | 3,681 ms |
| コンパイル使用メモリ | 106,368 KB |
| 実行使用メモリ | 18,048 KB |
| 最終ジャッジ日時 | 2024-12-30 13:26:33 |
| 合計ジャッジ時間 | 2,192 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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]--;
grid[y, x] = '-';
grid[x, y] = '-';
return Math.Min(first, second);
}
}
nanophoto12