結果
| 問題 | No.225 文字列変更(medium) |
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2015-06-12 23:25:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,899 bytes |
| 記録 | |
| コンパイル時間 | 767 ms |
| コンパイル使用メモリ | 89,580 KB |
| 実行使用メモリ | 15,232 KB |
| 最終ジャッジ日時 | 2024-07-06 15:56:46 |
| 合計ジャッジ時間 | 7,283 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 7 TLE * 1 -- * 11 |
ソースコード
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
#define input_init stringstream ss; string strtoken, token; istringstream is
#define input_line getline(cin, strtoken);is.str(strtoken);is.clear(istringstream::goodbit)
#define input_token(num) ss.str(""); ss.clear(stringstream::goodbit); getline(is, token, ','); ss << token; ss >> num
int dp[1001][1001] = { { 1 } };
int ii[1001][1001] = { { -1 } };
int jj[1001][1001] = { { -1 } };
int main(void){
int n,m;
string s;
string t;
cin >> n>>m >> s >> t;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (s[i] == t[j]){
dp[i + 1][j + 1] = dp[i][j] + 1;
ii[i + 1][j + 1] = i;
jj[i + 1][j + 1] = j;
}
else{
if (dp[i + 1][j] > dp[i][j + 1]){
dp[i + 1][j + 1] = dp[i + 1][j];
ii[i + 1][j + 1] = ii[i+1][j];
jj[i + 1][j + 1] = jj[i+1][j];
}
else{
dp[i + 1][j + 1] = dp[i][j+1];
ii[i + 1][j + 1] = ii[i][j+1];
jj[i + 1][j + 1] = jj[i][j+1];
}
}
}
}
string com;
int x=n, y=m;
while (ii[x][y] >= 0){
com = s[ii[x][y]]+com;
int t = x;
x = ii[t][y];
y = jj[t][y];
}
//cout << com << endl;
int len = (int)com.size();
int res = 0;
int nn = 0;
for (int i = 0; i < m; i++){
//cout << s << " " << t << " " << i <<" "<<nn<< endl;;
if (nn >= len){
res++;
}
else if (com[nn] == s[i] && com[nn] == t[i])nn++;
else if (s[i] == t[i])continue;
else if (com[nn] == s[i]){
s.insert(i, t.substr(i, 1));
res++;
}
else if (com[nn] == t[i]){
s.erase(i, 1);
i--;
res++;
}
else{
s[i] = t[i];
res++;
}
}
cout << res << endl;
return(0);
}
btk