結果
| 問題 |
No.225 文字列変更(medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-15 23:06:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 2,134 bytes |
| コンパイル時間 | 942 ms |
| コンパイル使用メモリ | 101,516 KB |
| 実行使用メモリ | 7,040 KB |
| 最終ジャッジ日時 | 2024-11-26 06:32:54 |
| 合計ジャッジ時間 | 1,824 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()
struct Edge{
int to;
int weight;
Edge(int t, int w) : to(t), weight(w){ }
};
struct edge{
int from;
int to;
int weight;
edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
template <class T>
inline bool chmin(T &a, T b){
if (a > b){
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b){
if (a < b){
a = b;
return true;
}
return false;
}
template <class T>
T gcd(T a, T b){
if( b==0 ) return a;
return gcd(b, a%b);
}
template <class T>
T lcm(T a, T b){
return (a*b)/gcd(a,b);
}
int INF = 1e9+7;
vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
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;
for(int i = -1; i<n; i++) for(int j = -1; j<m; j++){
if(i==-1 && j==-1) continue;
if(i>=0 && j>=0){
if(s[i]==t[j]) chmin(dp[i+1][j+1],dp[i][j]);
else chmin(dp[i+1][j+1],dp[i][j]+1);
}
if(i>=0) chmin(dp[i+1][j+1],dp[i][j+1]+1);
if(j>=0) chmin(dp[i+1][j+1],dp[i+1][j]+1);
}
cout << dp[n][m] << endl;
}