結果

問題 No.225 文字列変更(medium)
ユーザー kou6839kou6839
提出日時 2015-08-11 18:43:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 181 ms / 5,000 ms
コード長 695 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 78,876 KB
実行使用メモリ 60,676 KB
最終ジャッジ日時 2023-08-25 23:03:47
合計ジャッジ時間 6,918 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 174 ms
60,268 KB
testcase_01 AC 178 ms
60,420 KB
testcase_02 AC 140 ms
60,324 KB
testcase_03 AC 140 ms
60,100 KB
testcase_04 AC 140 ms
60,072 KB
testcase_05 AC 139 ms
60,368 KB
testcase_06 AC 139 ms
60,064 KB
testcase_07 AC 140 ms
60,340 KB
testcase_08 AC 141 ms
60,472 KB
testcase_09 AC 142 ms
60,248 KB
testcase_10 AC 140 ms
59,924 KB
testcase_11 AC 138 ms
60,404 KB
testcase_12 AC 178 ms
60,328 KB
testcase_13 AC 178 ms
60,124 KB
testcase_14 AC 180 ms
60,176 KB
testcase_15 AC 181 ms
60,508 KB
testcase_16 AC 179 ms
60,272 KB
testcase_17 AC 179 ms
60,168 KB
testcase_18 AC 178 ms
60,548 KB
testcase_19 AC 178 ms
60,176 KB
testcase_20 AC 179 ms
60,676 KB
testcase_21 AC 180 ms
60,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		S+="-";
		T+="-";
		int dp[][]=new int[1010][1010];
		for(int i=0;i<1010;i++) Arrays.fill(dp[i], 114514);
		dp[0][0]=0;
		for(int i=0;i<=n;i++){
			for(int j=0;j<=m;j++){
				if( S.charAt(i)==T.charAt(j)){
					dp[i+1][j+1]=Math.min(dp[i+1][j+1], dp[i][j]);
				}else{
					dp[i+1][j+1]=Math.min(dp[i+1][j+1], dp[i][j]+1);
				}
				dp[i+1][j]=Math.min(dp[i+1][j], dp[i][j]+1);
				dp[i][j+1]=Math.min(dp[i][j+1], dp[i][j]+1);

			}
		}
		System.out.println(dp[n][m]);

	}
}
0