結果

問題 No.874 正規表現間距離
ユーザー pockynypockyny
提出日時 2019-05-01 13:09:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,671 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 75,540 KB
実行使用メモリ 19,188 KB
最終ジャッジ日時 2023-08-11 04:15:46
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 12 ms
11,552 KB
testcase_17 AC 11 ms
11,560 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 33 ms
19,028 KB
testcase_26 AC 35 ms
19,144 KB
testcase_27 AC 45 ms
19,096 KB
testcase_28 AC 43 ms
19,064 KB
testcase_29 AC 47 ms
19,068 KB
testcase_30 AC 48 ms
19,092 KB
testcase_31 AC 49 ms
19,188 KB
testcase_32 AC 48 ms
19,080 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 15 ms
11,536 KB
testcase_37 AC 15 ms
11,540 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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-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][j-1],dp[i-1][j]});
			}
		}
	}
	cout << dp[n][m] << endl;
}
0