結果

問題 No.225 文字列変更(medium)
ユーザー btkbtk
提出日時 2015-06-12 23:24:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,893 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 88,612 KB
実行使用メモリ 15,156 KB
最終ジャッジ日時 2023-09-20 21:08:47
合計ジャッジ時間 7,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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);
}
0