結果

問題 No.225 文字列変更(medium)
ユーザー atsudr_2
提出日時 2017-12-20 10:51:10
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 112,916 KB
実行使用メモリ 28,308 KB
最終ジャッジ日時 2024-12-16 06:50:03
合計ジャッジ時間 2,314 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
class MainClass
{
    public static void Main(string[] args)
    {

        string[] s1 = Console.ReadLine().Split(' ');
        int n = int.Parse(s1[0]);
        int m = int.Parse(s1[1]);
        string S = Console.ReadLine();
        string T = Console.ReadLine();

        int[,] dp = new int[n + 1, m + 1];

        for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) dp[i, j] = 1000;
        dp[0, 0] = 0;
            
        for (int i = 0; i < n;i++)
        {
            for (int j = 0; j < m;j++)
            {
                if(S[i]==T[j])
                {
                    dp[i + 1, j + 1] = Math.Min(dp[i, j], dp[i + 1, j] + 1);
                    dp[i + 1, j + 1] = Math.Min(dp[i + 1, j + 1], dp[i, j + 1] + 1);
                }
                else
                {
                    dp[i + 1, j + 1] = Math.Min(dp[i, j] + 1, dp[i + 1, j] + 1);
                    dp[i + 1, j + 1] = Math.Min(dp[i + 1, j + 1], dp[i, j + 1] + 1);
                }

            }
        }

        Console.WriteLine(dp[n,m]);

    }
}
0