結果
| 問題 | No.225 文字列変更(medium) |
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-04 07:59:03 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,392 bytes |
| 記録 | |
| コンパイル時間 | 808 ms |
| コンパイル使用メモリ | 114,656 KB |
| 実行使用メモリ | 413,688 KB |
| 最終ジャッジ日時 | 2024-10-05 06:17:43 |
| 合計ジャッジ時間 | 15,647 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 TLE * 1 -- * 20 |
コンパイルメッセージ
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[] inputLength = Reader.GetInt();
this.Input1 = Reader.ReadLine();
this.Input2 = Reader.ReadLine();
int ans = this.GetAns(this.Input1, this.Input2);
Console.WriteLine(ans);
}
private Dictionary<string, Dictionary<string, int>> dic = new Dictionary<string, Dictionary<string, int>>();
private int GetAns(string target, string goal) {
if(!dic.ContainsKey(target)) {
dic.Add(target, new Dictionary<string, int>());
}
if(dic[target].ContainsKey(goal)) {
return dic[target][goal];
}
int ans = int.MaxValue;
if(target.Length == 0 && goal.Length > 0) {
ans = goal.Length;
} else if(target.Length > 0 && goal.Length == 0) {
ans = target.Length;
} else if(target.Length == 0 && goal.Length == 0) {
ans = 0;
} else
{
if(target[0] == goal[0]) {
int idx = 1;
for(int i=1; i<Math.Min(target.Length, goal.Length); i++) {
if(target[i] != goal[i]) {
break;
}
idx = i + 1;
}
ans = this.GetAns(target.Substring(idx), goal.Substring(idx));
}
if(goal.Length >= 2 && goal.IndexOf(target[0]) > 0)
{
int idx = goal.IndexOf(target[0]);
ans = Math.Min(ans, this.GetAns(target, goal.Substring(idx)) + idx);
}
if(target.Length >= 2 && target.IndexOf(goal[0]) > 0) {
int idx = target.IndexOf(goal[0]);
ans = Math.Min(ans, this.GetAns(target.Substring(idx), goal) + idx);
}
if(target[0] != goal[0]) {
ans = Math.Min(ans, this.GetAns(target.Substring(1), goal.Substring(1)) + 1);
}
}
this.dic[target].Add(goal, ans);
return ans;
}
private string Input1;
private string Input2;
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
14 16
pirikapirirara
poporinapeperuto
";
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番