結果

問題 No.43 野球の試合
ユーザー mbanmban
提出日時 2017-01-04 15:15:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 114 ms / 5,000 ms
コード長 2,693 bytes
コンパイル時間 3,330 ms
コンパイル使用メモリ 108,828 KB
実行使用メモリ 26,380 KB
最終ジャッジ日時 2023-08-22 13:45:08
合計ジャッジ時間 4,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,836 KB
testcase_01 AC 62 ms
19,740 KB
testcase_02 AC 62 ms
23,880 KB
testcase_03 AC 62 ms
22,076 KB
testcase_04 AC 62 ms
22,164 KB
testcase_05 AC 61 ms
22,204 KB
testcase_06 AC 62 ms
24,160 KB
testcase_07 AC 114 ms
26,380 KB
testcase_08 AC 62 ms
21,808 KB
testcase_09 AC 61 ms
21,728 KB
testcase_10 AC 62 ms
21,680 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.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;


class Magatro
{
    static int N = int.Parse(Console.ReadLine());
    static char[][] s;
    static void Main()
    {
        s = new char[N][];
 for(int i = 0; i < N; i++)
        {
            s[i] = Console.ReadLine().ToArray();
        }
/* for(int i = 0; i < N; i++)
        {
            if (s[0][i] == '-')
            {
                s[0][i] = 'o';
                s[i][0] = 'x';
            }
        }
        */
        List<XY> L = new List<XY>(); 
 for(int i = 0; i < N - 1; i++)
        {
            for(int j = i + 1; j < N; j++)
            {
                if (s[i][j] == '-')
                {
                    L.Add(new XY(j, i));
                }
            }
        }
        int loop = (int)Math.Pow(2, L.Count);
        int min = int.MaxValue;
        for(int i = 0; i < loop; i++)
        {
            int q = i;
            char[][] copy = s.ToArray();
            for(int j = 0; j < L.Count; j++)
            {
                if (q % 2 == 1)
                {
                    copy[L[j].Y][L[j].X] = 'o';
                    copy[L[j].X][L[j].Y] = 'x';
                }
                else
                {
                    copy[L[j].Y][L[j].X] = 'x';
                    copy[L[j].X][L[j].Y] = 'o';
                }
                q /= 2;
            }
            min = Math.Min(min, J(copy));
        }
        Console.WriteLine(min);
    }
    static int J(char[][] ss)
    {
        T[] Temp = new T[N];
        for(int i = 0; i < N; i++)
        {
            Temp[i] = new T(i);
        }
        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j < N; j++)
            {
                if (i == j)
                {
                    continue;
                }
                if(ss[j][i]== 'o')
                {
                    Temp[i].c++;
                }
            }
        }
        T[] copy = Temp.ToArray();
        Array.Sort(copy, (a, b) => a.c.CompareTo(b.c));
        int ans = 0;
        int m = int.MaxValue;
        for(int i = 0; i < N; i++)
        {
            if (m != copy[i].c)
            {
                ans++;
                m = copy[i].c;
            }
            if (copy[i].index == 0)
            {
                return ans;
            }
        }
        return -1;
    }
}
struct XY
{
    public int X, Y;
    public XY(int x,int y)
    {
        X = x;
        Y = y;
    }
}
struct T
{
    public int index, c;
    public T(int i)
    {
        c = 0;
        index = i;
    }
}
0