結果
| 問題 | 
                            No.225 文字列変更(medium)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             mban
                         | 
                    
| 提出日時 | 2017-04-25 22:33:25 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 129 ms / 5,000 ms | 
| コード長 | 1,175 bytes | 
| コンパイル時間 | 2,092 ms | 
| コンパイル使用メモリ | 110,716 KB | 
| 実行使用メモリ | 35,196 KB | 
| 最終ジャッジ日時 | 2024-09-13 09:18:59 | 
| 合計ジャッジ時間 | 3,927 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
コンパイルメッセージ
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;
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];
    }
}
            
            
            
        
            
mban