結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-03 21:55:53 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,339 bytes |
| コンパイル時間 | 957 ms |
| コンパイル使用メモリ | 111,628 KB |
| 実行使用メモリ | 36,228 KB |
| 最終ジャッジ日時 | 2024-10-05 06:00:28 |
| 合計ジャッジ時間 | 7,695 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 2 TLE * 1 -- * 12 |
コンパイルメッセージ
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 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;
}
}
for(int i=0; i<target.Count; i++) {
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();
}
}
14番