結果

問題 No.874 正規表現間距離
ユーザー pockynypockyny
提出日時 2019-05-01 12:46:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,696 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 75,756 KB
実行使用メモリ 23,280 KB
最終ジャッジ日時 2023-08-11 04:15:36
合計ジャッジ時間 6,102 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,764 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 712 ms
11,596 KB
testcase_17 AC 719 ms
11,492 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 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string A,B;
int dp[2010][2010];
int bit(string s,int i){
	if(s[i]=='*') return 2;
	if(s[i]=='?') return 1;
	return 0;
}
int ch(int i, int j){
	return 3*bit(A,i) + bit(B,j);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,j,n,m;
	cin >> A >> B;
	n = A.size(); m = B.size();
	for(i=0;i<=n;i++){
		for(j=0;j<=m;j++){
			dp[i][j] = 100000;
		}
	}
	dp[0][0] = 0;
	for(i=1;i<=m;i++){
		dp[0][i] = dp[0][i-1] + 1;
		if(B[i-1]=='?' || B[i-1]=='*') dp[0][i]--;
	}
	for(i=1;i<=n;i++){
		dp[i][0] = dp[i-1][0] + 1;
		if(A[i-1]=='?' || A[i-1]=='*') dp[i][0]--;
	}
	dp[0][0] = 0;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(ch(i-1,j-1)==0){//moji_moji
				if(A[i-1]==B[j-1]){
					dp[i][j] = dp[i-1][j-1];
				}else{
					dp[i][j] = min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]}) + 1;
				}
			}
			if(ch(i-1,j-1)==1){//moji_?
				dp[i][j] = min(dp[i][j-1],dp[i][j-2]);
			}
			if(ch(i-1,j-1)==2){//moji_*
				dp[i][j] = min({dp[i][j-2],dp[i][j-1],dp[i-1][j] + (A[i-1]!=B[j-2])});
			}
			if(ch(i-1,j-1)==3){//?_moji
				dp[i][j] = min({dp[i-1][j],dp[i-2][j]});
			}
			if(ch(i-1,j-1)==4){//?_?
				dp[i][j] = min({dp[i-1][j-1],dp[i-2][j-1],dp[i-1][j-2],dp[i-2][j-2]});
			}
			if(ch(i-1,j-1)==5){//?_*
				dp[i][j] = min({dp[i-1][j],dp[i-2][j]});
			}
			if(ch(i-1,j-1)==6){//*_moji
				dp[i][j] = min({dp[i-2][j],dp[i-1][j],dp[i][j-1] + (A[i-2]!=B[j-1])});
			}
			if(ch(i-1,j-1)==7){//*_?
				dp[i][j] = min({dp[i][j-1],dp[i][j-2]});
			}
			if(ch(i-1,j-1)==8){//*_*
				dp[i][j] = min({dp[i-2][j-2],dp[i-2][j-1],dp[i-1][j-2],dp[i-1][j-1],dp[i][j-1],dp[i-1][j]});
			}
		}
	}
	cout << dp[n][m] << endl;
}
0