結果

問題 No.225 文字列変更(medium)
ユーザー nagatelu1020nagatelu1020
提出日時 2019-10-30 12:00:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 2,034 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 146,192 KB
実行使用メモリ 11,624 KB
最終ジャッジ日時 2023-10-12 23:42:35
合計ジャッジ時間 2,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,384 KB
testcase_01 AC 8 ms
11,492 KB
testcase_02 AC 5 ms
11,540 KB
testcase_03 AC 5 ms
11,352 KB
testcase_04 AC 4 ms
11,408 KB
testcase_05 AC 4 ms
11,396 KB
testcase_06 AC 5 ms
11,384 KB
testcase_07 AC 5 ms
11,392 KB
testcase_08 AC 4 ms
11,388 KB
testcase_09 AC 5 ms
11,396 KB
testcase_10 AC 5 ms
11,352 KB
testcase_11 AC 5 ms
11,328 KB
testcase_12 AC 9 ms
11,492 KB
testcase_13 AC 10 ms
11,448 KB
testcase_14 AC 9 ms
11,328 KB
testcase_15 AC 8 ms
11,360 KB
testcase_16 AC 8 ms
11,340 KB
testcase_17 AC 8 ms
11,624 KB
testcase_18 AC 8 ms
11,388 KB
testcase_19 AC 9 ms
11,392 KB
testcase_20 AC 9 ms
11,356 KB
testcase_21 AC 10 ms
11,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define ll long long
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
ll keta(ll num){ ll k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n, m;
    ll dp[1010][1010];
    string s, t;
    cin >> n >> m >> s >> t;

    rep(i, 1010){
        rep(j, 1010){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;

    reps(i, -1, n){
        reps(j, -1, m){
            if(i == -1 && j == -1) continue;
            if(i >= 0 && j >= 0){
                if(s[i] == t[j]) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);
                else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1);
            }
            if(i >= 0) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1] + 1);
            if(j >= 0) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j] + 1);
        }
    }

    cout << dp[n][m] << endl;

    return 0;
}
0