結果

問題 No.43 野球の試合
ユーザー nanophoto12nanophoto12
提出日時 2014-10-29 00:15:57
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,226 bytes
コンパイル時間 2,775 ms
コンパイル使用メモリ 107,288 KB
実行使用メモリ 22,756 KB
最終ジャッジ日時 2023-08-28 22:57:41
合計ジャッジ時間 3,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
20,716 KB
testcase_01 AC 55 ms
20,648 KB
testcase_02 AC 55 ms
22,756 KB
testcase_03 AC 54 ms
20,768 KB
testcase_04 AC 54 ms
20,808 KB
testcase_05 AC 54 ms
22,756 KB
testcase_06 WA -
testcase_07 AC 55 ms
20,648 KB
testcase_08 AC 54 ms
20,792 KB
testcase_09 AC 54 ms
18,792 KB
testcase_10 AC 54 ms
20,720 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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);
    }
}

0