結果

問題 No.43 野球の試合
ユーザー 14番14番
提出日時 2016-04-04 23:04:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 217 ms / 5,000 ms
コード長 3,737 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 112,724 KB
実行使用メモリ 29,996 KB
最終ジャッジ日時 2024-04-14 21:34:55
合計ジャッジ時間 2,079 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
26,128 KB
testcase_01 AC 29 ms
24,092 KB
testcase_02 AC 29 ms
23,852 KB
testcase_03 AC 30 ms
26,248 KB
testcase_04 AC 30 ms
24,048 KB
testcase_05 AC 29 ms
23,984 KB
testcase_06 AC 31 ms
26,004 KB
testcase_07 AC 217 ms
29,996 KB
testcase_08 AC 30 ms
25,880 KB
testcase_09 AC 29 ms
23,800 KB
testcase_10 AC 29 ms
26,220 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.Generic;
using System.Text;

public class Program
{
    public void Proc(){
        
        Reader.IsDebug = false;
        
        int teamCount = int.Parse(Reader.ReadLine());
        
        char[,] map = new char[teamCount, teamCount];
        
        for(int i=0; i<teamCount; i++) {
            string temp = Reader.ReadLine();
            for(int j=0; j<teamCount; j++) {
                map[i,j] = temp[j];
            }
        }
        int ans = GetAns(0,1,map);
        Console.WriteLine(ans);
    }
    
    private int GetAns(int row, int col, char[,] target) {
        if(row < target.GetLength(0) - 1 && col < target.GetLength(1)) {
            int ans = int.MaxValue;
            for(int i=row; i<target.GetLength(0)-1; i++) {
                for(int j=i+1; j<target.GetLength(1); j++) {
                    if(i==row && j < col) {
                        continue;
                    }
                    if(target[i,j] == '-') {
                        int nextRow = i;
                        int nextCol = j + 1;
                        if(nextCol >= target.GetLength(1)) {
                            nextRow++;
                            nextCol = nextRow + 1;
                        }
                        char[,] work = this.CloneCopy(target);
                        work[i,j] = 'o';
                        work[j,i] = 'x';
                        ans = Math.Min(this.GetAns(nextRow, nextCol, work), ans);
                        work[i, j] = 'x';
                        work[j, i] = 'o'; 
                        ans = Math.Min(this.GetAns(nextRow, nextCol, work), ans);
                        return ans;
                    }
                }
            }
        }
        
        Dictionary<int, List<int>> winCount = new Dictionary<int, List<int>>();
        List<int> keyList = new List<int>();
        for(int i=0; i<target.GetLength(0); i++) {
            int num = 0;
            for(int j=0; j<target.GetLength(1); j++) {
                if(target[i,j]=='o') {
                    num++;
                }
            }
            if(!winCount.ContainsKey(num)) {
                winCount.Add(num, new List<int>());
                keyList.Add(num);
            } 
            winCount[num].Add(i);
        }
        keyList.Sort();
        keyList.Reverse();
        for(int i=0; i<keyList.Count; i++) {
            int key = keyList[i];
            if(winCount[key].Contains(0)) {
                return i+1;
            }
        }
        return target.GetLength(0);
    }
    
    private char[,] CloneCopy(char[,] src) {
        char[,] ret = new char[src.GetLength(0), src.GetLength(1)];
        for(int i=0; i<src.GetLength(0); i++) {
            for(int j=0; j<src.GetLength(1); j++) {
                ret[i,j] = src[i,j];
            }
        }
        return ret;
    }
    
    
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

class Reader
{
    public static bool IsDebug = true;
    
    private static System.IO.StringReader sr;
    
    public static string ReadLine() {
        if(IsDebug) {
            if(sr == null) {
                sr = new System.IO.StringReader(initStr.Trim());
            }
            return sr.ReadLine();
        } else {
            return Console.ReadLine();
        }
    }
    
    public static int[] GetInt(char delimiter = ' ') {
        string[] inpt = ReadLine().Split(delimiter);
        int[] ret = new int[inpt.Length];
        for(int i=0; i<inpt.Length; i++) {
            ret[i] = int.Parse(inpt[i]);
        }
        return ret;
    }
    
    private static string initStr = @"


4
#-xx
-#x-
oo#-
o--#



";
}

0