結果

問題 No.225 文字列変更(medium)
ユーザー norikamenorikame
提出日時 2020-08-12 21:08:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,698 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 170,164 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-04-18 00:51:24
合計ジャッジ時間 2,350 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 6 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 8 ms
7,040 KB
testcase_13 AC 9 ms
7,424 KB
testcase_14 AC 9 ms
7,168 KB
testcase_15 AC 8 ms
7,168 KB
testcase_16 AC 8 ms
7,168 KB
testcase_17 AC 8 ms
7,168 KB
testcase_18 AC 8 ms
7,040 KB
testcase_19 AC 7 ms
7,168 KB
testcase_20 AC 7 ms
6,948 KB
testcase_21 AC 9 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    vector<vi> dp(n+1, vi(m+1, INF));
    dp[0][0] = 0;
    for (int i=-1; i<n; ++i) for (int j=-1; j<m; ++j) {
        if (i==-1 && j==-1) continue;
        if (i!=-1 && j!=-1) {
            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!=-1) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1]+1);
        if (j!=-1) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j]+1); 
    }
    cout << dp[n][m] << endl;
    return 0;
}
0