結果

問題 No.225 文字列変更(medium)
ユーザー 沙耶花沙耶花
提出日時 2021-11-16 19:41:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 4,039 ms
コンパイル使用メモリ 259,676 KB
実行使用メモリ 7,284 KB
最終ジャッジ日時 2023-08-22 20:04:46
合計ジャッジ時間 5,286 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,044 KB
testcase_01 AC 6 ms
5,932 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 7 ms
6,868 KB
testcase_13 AC 8 ms
7,152 KB
testcase_14 AC 7 ms
7,284 KB
testcase_15 AC 7 ms
6,972 KB
testcase_16 AC 7 ms
7,212 KB
testcase_17 AC 7 ms
6,884 KB
testcase_18 AC 7 ms
6,792 KB
testcase_19 AC 7 ms
6,948 KB
testcase_20 AC 7 ms
6,744 KB
testcase_21 AC 7 ms
6,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	
	vector dp(n+1,vector<int>(m+1,Inf));
	dp[0][0] = 0;
	
	rep(i,n+1){
		rep(j,m+1){
			if(i!=n)dp[i+1][j] = min(dp[i+1][j],dp[i][j]+1);
			if(j!=m)dp[i][j+1] = min(dp[i][j+1],dp[i][j]+1);
			if(i!=n&&j!=m){
				int cost = 0;
				if(s[i]!=t[j])cost = 1;
				dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+cost);
			}
		}
	}
	cout<<dp[n][m]<<endl;
	
	return 0;
}
0