結果

問題 No.225 文字列変更(medium)
ユーザー mbanmban
提出日時 2017-04-25 22:33:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 165 ms / 5,000 ms
コード長 1,175 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 103,788 KB
実行使用メモリ 32,588 KB
最終ジャッジ日時 2023-10-11 10:11:48
合計ジャッジ時間 6,048 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
26,544 KB
testcase_01 AC 128 ms
27,368 KB
testcase_02 AC 53 ms
23,372 KB
testcase_03 AC 54 ms
23,256 KB
testcase_04 AC 53 ms
21,360 KB
testcase_05 AC 52 ms
23,260 KB
testcase_06 AC 53 ms
21,208 KB
testcase_07 AC 53 ms
21,220 KB
testcase_08 AC 53 ms
23,192 KB
testcase_09 AC 53 ms
21,320 KB
testcase_10 AC 55 ms
21,324 KB
testcase_11 AC 54 ms
21,212 KB
testcase_12 AC 158 ms
32,588 KB
testcase_13 AC 165 ms
30,708 KB
testcase_14 AC 161 ms
28,592 KB
testcase_15 AC 156 ms
30,544 KB
testcase_16 AC 158 ms
28,632 KB
testcase_17 AC 153 ms
28,640 KB
testcase_18 AC 151 ms
30,364 KB
testcase_19 AC 156 ms
26,360 KB
testcase_20 AC 148 ms
28,272 KB
testcase_21 AC 155 ms
28,408 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    public void Solve()
    {
        Console.ReadLine();
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        Console.WriteLine(LenenshteinDistance(s, t));
    }


    private int LenenshteinDistance(string a, string b)
    {
        int[,] dp = new int[a.Length + 1, b.Length + 1];

        for (int i = 0; i <= a.Length; i++)
        {
            dp[i, 0] = i;
        }

        for (int i = 0; i <= b.Length; i++)
        {
            dp[0, i] = i;
        }

        for (int i = 1; i <= a.Length; i++)
        {
            for (int j = 1; j <= b.Length; j++)
            {
                int cost = a[i - 1] == b[j - 1] ? 0 : 1;

                dp[i, j] = (new int[] { dp[i - 1, j] + 1, dp[i, j - 1]+1, dp[i - 1, j - 1] + cost }).Min();
            }
        }

        return dp[a.Length, b.Length];
    }
}

0