結果

問題 No.874 正規表現間距離
ユーザー chocoruskchocorusk
提出日時 2019-08-30 22:54:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,718 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 98,388 KB
実行使用メモリ 19,452 KB
最終ジャッジ日時 2023-08-14 07:07:18
合計ジャッジ時間 2,802 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 6 ms
11,660 KB
testcase_17 AC 8 ms
12,688 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 21 ms
19,188 KB
testcase_26 AC 16 ms
19,144 KB
testcase_27 AC 27 ms
19,188 KB
testcase_28 AC 29 ms
19,164 KB
testcase_29 AC 28 ms
19,452 KB
testcase_30 AC 28 ms
19,184 KB
testcase_31 AC 30 ms
19,172 KB
testcase_32 AC 31 ms
19,248 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
5,484 KB
testcase_36 AC 10 ms
12,748 KB
testcase_37 AC 10 ms
12,508 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 2 ms
4,376 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