結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-03 19:49:48 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,403 bytes |
| コンパイル時間 | 811 ms |
| コンパイル使用メモリ | 114,356 KB |
| 実行使用メモリ | 29,440 KB |
| 最終ジャッジ日時 | 2024-10-05 05:38:10 |
| 合計ジャッジ時間 | 14,589 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 5 WA * 7 TLE * 1 -- * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番