結果

問題 No.43 野球の試合
ユーザー nanophoto12nanophoto12
提出日時 2014-10-29 23:29:45
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 2,317 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 103,012 KB
実行使用メモリ 24,856 KB
最終ジャッジ日時 2023-08-28 23:09:54
合計ジャッジ時間 3,571 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
22,624 KB
testcase_01 AC 57 ms
20,824 KB
testcase_02 AC 56 ms
20,656 KB
testcase_03 AC 57 ms
20,640 KB
testcase_04 AC 56 ms
20,640 KB
testcase_05 AC 56 ms
22,788 KB
testcase_06 AC 56 ms
22,780 KB
testcase_07 AC 85 ms
24,856 KB
testcase_08 AC 57 ms
22,864 KB
testcase_09 AC 57 ms
20,636 KB
testcase_10 AC 58 ms
22,620 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];
            }
        }
        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.Item2));
            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);
    }
}

0