結果

問題 No.874 正規表現間距離
ユーザー chocoruskchocorusk
提出日時 2019-08-30 22:54:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,718 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 101,628 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-05-01 19:48:50
合計ジャッジ時間 2,302 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
19,328 KB
testcase_01 AC 10 ms
19,456 KB
testcase_02 AC 10 ms
19,456 KB
testcase_03 AC 10 ms
19,328 KB
testcase_04 AC 11 ms
19,328 KB
testcase_05 AC 10 ms
19,328 KB
testcase_06 AC 11 ms
19,456 KB
testcase_07 AC 11 ms
19,328 KB
testcase_08 AC 12 ms
19,328 KB
testcase_09 AC 11 ms
19,200 KB
testcase_10 AC 11 ms
19,456 KB
testcase_11 AC 12 ms
19,456 KB
testcase_12 AC 11 ms
19,456 KB
testcase_13 AC 12 ms
19,456 KB
testcase_14 AC 11 ms
19,328 KB
testcase_15 AC 10 ms
19,456 KB
testcase_16 AC 13 ms
19,456 KB
testcase_17 AC 14 ms
19,456 KB
testcase_18 AC 11 ms
19,456 KB
testcase_19 AC 11 ms
19,328 KB
testcase_20 AC 10 ms
19,328 KB
testcase_21 AC 10 ms
19,456 KB
testcase_22 AC 11 ms
19,456 KB
testcase_23 AC 11 ms
19,200 KB
testcase_24 AC 11 ms
19,456 KB
testcase_25 AC 24 ms
19,200 KB
testcase_26 AC 22 ms
19,456 KB
testcase_27 AC 27 ms
19,456 KB
testcase_28 AC 24 ms
19,328 KB
testcase_29 AC 26 ms
19,328 KB
testcase_30 AC 26 ms
19,328 KB
testcase_31 AC 27 ms
19,456 KB
testcase_32 AC 28 ms
19,456 KB
testcase_33 AC 11 ms
19,456 KB
testcase_34 AC 11 ms
19,456 KB
testcase_35 AC 11 ms
19,456 KB
testcase_36 AC 14 ms
19,200 KB
testcase_37 AC 17 ms
19,456 KB
testcase_38 AC 11 ms
19,328 KB
testcase_39 AC 11 ms
19,328 KB
testcase_40 AC 11 ms
19,328 KB
testcase_41 AC 11 ms
19,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string a, b; cin>>a>>b;
	int n=a.size(), m=b.size();
	int dp[2020][2020];
	dp[0][0]=0;
	for(int i=0; i<n; i++){
		if(!('a'<=a[i] && a[i]<='z')){
			dp[i+1][0]=dp[i][0];
			continue;
		}
		if(i+1<n && !('a'<=a[i+1] && a[i+1]<='z')) dp[i+1][0]=dp[i][0];
		else dp[i+1][0]=dp[i][0]+1;
	}
	for(int i=0; i<m; i++){
		if(!('a'<=b[i] && b[i]<='z')){
			dp[0][i+1]=dp[0][i];
			continue;
		}
		if(i+1<m && !('a'<=b[i+1] && b[i+1]<='z')) dp[0][i+1]=dp[0][i];
		else dp[0][i+1]=dp[0][i]+1;
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!('a'<=a[i] && a[i]<='z')){
				dp[i+1][j+1]=dp[i][j+1];
				continue;
			}
			if(!('a'<=b[j] && b[j]<='z')){
				dp[i+1][j+1]=dp[i+1][j];
				continue;
			}
			dp[i+1][j+1]=min({dp[i][j+1]+1, dp[i+1][j]+1, dp[i][j]+1});
			if(a[i]==b[j]) dp[i+1][j+1]=min(dp[i+1][j+1], dp[i][j]);
			if(i+1<n && !('a'<=a[i+1] && a[i+1]<='z')) dp[i+1][j+1]=min(dp[i+1][j+1], dp[i][j+1]);
			if(j+1<m && !('a'<=b[j+1] && b[j+1]<='z')) dp[i+1][j+1]=min(dp[i+1][j+1], dp[i+1][j]);
			if(i+1<n && a[i+1]=='*' && a[i]==b[j]) dp[i+1][j+1]=min(dp[i+1][j+1], dp[i+1][j]);
			if(j+1<m && b[j+1]=='*' && a[i]==b[j]) dp[i+1][j+1]=min(dp[i+1][j+1], dp[i][j+1]);
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}
0