結果

問題 No.205 マージして辞書順最小
ユーザー 14番14番
提出日時 2016-05-03 21:58:12
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,451 bytes
コンパイル時間 1,212 ms
コンパイル使用メモリ 112,248 KB
実行使用メモリ 55,028 KB
最終ジャッジ日時 2024-04-15 11:04:01
合計ジャッジ時間 7,815 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
26,060 KB
testcase_01 AC 25 ms
23,908 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Linq;
 
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int inputCount = int.Parse(Reader.ReadLine());
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<inputCount; i++) {
            string tmp = Reader.ReadLine();
            this.InputList.Add(tmp);
        }
        InputList.Sort();
        this.MinAns = string.Join(string.Empty, InputList);
        string ans = this.GetAns(InputList, string.Empty);
        Console.WriteLine(this.MinAns);
    }
    
    private String GetAns(List<String> target, string totyu) {
        int len = Math.Min(totyu.Length, this.MinAns.Length);
        for(int i=0; i<len; i++) {
            if(totyu[i] > MinAns[i]) {
                return string.Empty;
            }
            if(totyu[i] < MinAns[i]) {
                MinAns = totyu;
                break;
            }
        }
        if(totyu.Length > this.MinAns.Length) {
            MinAns = totyu;
        }
        
        string ans = string.Empty;
        if(target.Count == 1) {
            ans = totyu + target[0];
            if(this.MinAns.Length < ans.Length && ans.StartsWith(this.MinAns))  {
                this.MinAns = ans;
                return ans;
            } else if(this.MinAns.CompareTo(ans) > 0) {
                this.MinAns = ans;
                return ans;
            } else
            {
                return string.Empty;
            }
        }
        
        char first = target[0][0];
        for(int i=0; i<target.Count; i++) {
            if(first != target[i][0]) {
                break;
            }
            List<string> subList = new List<string>(target);
            if(subList[i].Length == 1) {
                subList.RemoveAt(i);
            } else
            {
                subList[i] = subList[i].Substring(1);
            }
            string tmp = this.GetAns(subList, totyu + target[i][0]);
            if(tmp.Length > 0) {
                if(ans.Length == 0  || tmp.CompareTo(ans) < 0) {
                    ans = tmp;
                }
            }
        }
        return ans;
    }
    
    private string MinAns = string.Empty;
    private List<string> InputList = new List<string>();
    


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


2
ac
bd


 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0