結果

問題 No.205 マージして辞書順最小
ユーザー 14番14番
提出日時 2016-05-03 19:49:48
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,403 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 110,848 KB
実行使用メモリ 29,696 KB
最終ジャッジ日時 2024-04-15 10:53:38
合計ジャッジ時間 16,954 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
19,072 KB
testcase_01 AC 33 ms
19,200 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 35 ms
18,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 AC 2,589 ms
23,744 KB
testcase_12 TLE -
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 itemCount = int.Parse(Reader.ReadLine());
        
        List<string> inputList = new List<string>();
        for(int i=0; i<itemCount; i++) {
            inputList.Add(Reader.ReadLine());
        }
        StringBuilder sb = new StringBuilder();
        while (inputList.Max(a=>a.Length) > 0)
        {
            int idx = this.SelectFirstByDic(inputList);
            sb.Append(inputList[idx][0]);
            inputList[idx] = inputList[idx].Substring(1);
        }
        Console.WriteLine(sb.ToString());

    }
    
    private int SelectFirstByDic(List<string> target) {
        Dictionary<int, string> dic = new Dictionary<int, string>();
        target.ForEach(a=>dic.Add(dic.Count, a));
        List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>(dic.ToList());
        list.Sort((a,b)=>{
            if(a.Value.Equals(b.Value)) {
                return 0;
            }
            if(a.Value.Length == 0) {
                return 1;
            }
            if(b.Value.Length == 0) {
                return -1;
            }
            int len = Math.Min(a.Value.Length ,b.Value.Length);
            for(int i=0; i<len; i++) {
                if(a.Value[i] < b.Value[i]) {
                    return -1;
                } else if(a.Value[i] > b.Value[i]) {
                    return 1;
                }
            }
            KeyValuePair<int, string> sht = (a.Value.Length < b.Value.Length)?a:b;
            KeyValuePair<int, string> lng = (a.Key == sht.Key)?b:a;
            foreach (KeyValuePair<int, string> item in dic)
            {
                if(item.Key != sht.Key && item.Key != lng.Key) {
                    if((sht.Value + item.Value).CompareTo(lng.Value) < 0) {
                        if(sht.Key == a.Key) {
                            return - 1;
                        } else
                        {
                            return 1;
                        }
                    }
                }
            }
            return (lng.Key == a.Key)?-1:1;
        });
        return list[0].Key;
    }


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


2
az
za

 
";
        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