結果

問題 No.225 文字列変更(medium)
ユーザー seiyuseiyu
提出日時 2020-12-16 01:29:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,243 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 172,456 KB
実行使用メモリ 7,068 KB
最終ジャッジ日時 2023-10-20 08:34:51
合計ジャッジ時間 3,003 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 7 ms
5,876 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 10 ms
6,932 KB
testcase_14 AC 11 ms
6,932 KB
testcase_15 WA -
testcase_16 AC 10 ms
6,932 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 AC 10 ms
6,668 KB
testcase_21 AC 10 ms
6,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

int main(){
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, inf));

    dp[0][0] = 0;

    rep(i, n + 1){
        rep(j, m + 1){
            if(i < n){
                chmin(dp[i + 1][j], dp[i][j] + 1);
            }
            if(j < n){
                chmin(dp[i][j + 1], dp[i][j] + 1);
            }
            if(i < n && j < m){
                chmin(dp[i + 1][j + 1], dp[i][j] + (s[i] != t[j]));
            }
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}
0