結果
| 問題 |
No.874 正規表現間距離
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-08-30 22:23:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,536 bytes |
| コンパイル時間 | 1,891 ms |
| コンパイル使用メモリ | 196,384 KB |
| 最終ジャッジ日時 | 2025-01-07 15:58:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 WA * 2 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
const Int MAX = 2020;
const Int INF = 1e9;
Int dp[MAX][MAX];
signed main(){
string s,t;
cin>>s>>t;
for(Int i=0;i<MAX;i++)
for(Int j=0;j<MAX;j++)
dp[i][j]=INF;
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
Int n=s.size();
Int m=t.size();
s+='&';
t+='%';
dp[0][0]=0;
for(Int i=0;i<=n;i++){
for(Int j=0;j<=m;j++){
//cout<<i<<" "<<j<<":"<<dp[i][j]<<endl;
if(s[i]=='?'){
chmin(dp[i+2][j],dp[i][j]);
if(t[j]!='?'&&t[j]!='*')
chmin(dp[i+2][j+1],dp[i][j]+(s[i+1]!=t[j]));
}
if(t[j]=='?'){
chmin(dp[i][j+2],dp[i][j]);
if(s[i]!='?'&&s[i]!='*')
chmin(dp[i+1][j+2],dp[i][j]+(s[i]!=t[j+1]));
}
if(s[i]=='*'){
chmin(dp[i+2][j],dp[i][j]);
if(t[j]!='?'&&t[j]!='*')
chmin(dp[i+0][j+1],dp[i][j]+(s[i+1]!=t[j]));
}
if(t[j]=='*'){
chmin(dp[i][j+2],dp[i][j]);
if(s[i]!='?'&&s[i]!='*')
chmin(dp[i+1][j+0],dp[i][j]+(s[i]!=t[j+1]));
}
if(s[i]!='?'&&s[i]!='*'){
if(t[j]!='?'&&t[j]!='*'){
chmin(dp[i+1][j+0],dp[i][j]+1);
chmin(dp[i+0][j+1],dp[i][j]+1);
chmin(dp[i+1][j+1],dp[i][j]+(s[i]!=t[j]));
}
}
}
}
cout<<dp[n][m]<<endl;
return 0;
}
beet