結果

問題 No.225 文字列変更(medium)
ユーザー BantakoBantako
提出日時 2019-01-09 20:23:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 547 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 165,880 KB
実行使用メモリ 7,108 KB
最終ジャッジ日時 2023-08-15 16:58:42
合計ジャッジ時間 2,370 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,804 KB
testcase_01 AC 5 ms
5,840 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 5 ms
6,860 KB
testcase_13 AC 5 ms
7,092 KB
testcase_14 AC 5 ms
6,988 KB
testcase_15 AC 5 ms
6,824 KB
testcase_16 AC 5 ms
7,004 KB
testcase_17 AC 5 ms
6,928 KB
testcase_18 AC 4 ms
6,768 KB
testcase_19 AC 5 ms
7,108 KB
testcase_20 AC 5 ms
6,656 KB
testcase_21 AC 5 ms
6,828 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    string S,T;
    cin >> N >> M >> S >> T;
    int dp[N+1][M+1] = {};
    rep(i,0,N+1)dp[i][0] = i;
    rep(i,0,M+1)dp[0][i] = i;

    rep(i,1,N+1)rep(j,1,M+1){
        int cost = !(S[i-1] == T[j-1]);
        dp[i][j] = min({
            dp[i-1][j] + 1,
            dp[i][j-1] + 1,
            dp[i-1][j-1] + cost
        });
    }
    cout << dp[N][M] << endl;
}
0