結果
| 問題 | 
                            No.874 正規表現間距離
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-04-18 11:55:10 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 4,517 bytes | 
| コンパイル時間 | 1,824 ms | 
| コンパイル使用メモリ | 177,256 KB | 
| 実行使用メモリ | 18,944 KB | 
| 最終ジャッジ日時 | 2024-10-03 23:21:30 | 
| 合計ジャッジ時間 | 3,460 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 27 WA * 11 | 
ソースコード
/*
   ∫ ∫ ∫
   ノヽ
  (_  )
 (_    )
(______ )
 ヽ(´・ω・)ノ 
   |  /
   UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string U,V;
    cin >> U >> V;
    string S="",T="";
    vector<int> S_info,T_info;
    for(auto s:U){
        if(s=='?'){
            S_info.back()=1;
        }else if(s=='*') S_info.back()=2;
        else{
            S_info.emplace_back(0);
            S+=s;
        }
    }
    for(auto s:V){
        if(s=='?'){
            T_info.back()=1;
        }else if(s=='*') T_info.back()=2;
        else {
            T_info.emplace_back(0);
            T+=s;
        }
    }
    debug("A")
    int N=S.size(), M=T.size();
    vector<vector<int>>  DP(N+1,vector<int>(M+1,inf));
    DP[0][0] = 0;
    REP(i,N){
        REP(j,M){
            chmin(DP[i+1][j],DP[i][j]+1);
            chmin(DP[i][j+1],DP[i][j]+1);
            if(S_info[i]==0 and T_info[j]==0){ //s t
                if(S[i]==T[j]) chmin(DP[i+1][j+1],DP[i][j]);
                if(S[i]==T[j]) chmin(DP[i+1][j+1],DP[i][j]+1);
            }else if(S_info[i]==1 and T_info[j]==0){ //? t
                chmin(DP[i+1][j],DP[i][j]); //?なのでマッチせずiだけ進める
                if(S[i]==T[j]) chmin(DP[i+1][j+1],DP[i][j]);
                else chmin(DP[i+1][j+1],DP[i][j]+1);
            }else if(S_info[i]==0 and T_info[j]==1){ //s ?
                chmin(DP[i][j+1],DP[i][j]); //?なのでマッチせずjだけ進める
                if(S[i]==T[j]) chmin(DP[i+1][j+1],DP[i][j]);
                else chmin(DP[i+1][j+1],DP[i][j]+1);
            }else if(S_info[i]==2 and T_info[j]==0){ //* t
                chmin(DP[i+1][j],DP[i][j]); //*なのでマッチせずiだけ進める
                if(S[i]==T[j]) chmin(DP[i][j+1],DP[i][j]), chmin(DP[i+1][j+1],DP[i][j]); //jだけ進めるので*を次もまた使える
                else chmin(DP[i][j+1],DP[i][j]+1), chmin(DP[i+1][j+1],DP[i][j]+1); //jだけ進めるので*を次もまた使える
            }else if(S_info[i]==0 and T_info[j]==2){ //s *
                chmin(DP[i][j+1],DP[i][j]); //*なのでマッチせずjだけ進める
                if(S[i]==T[j]) chmin(DP[i+1][j],DP[i][j]), chmin(DP[i+1][j+1],DP[i][j]); //iだけ進めるので*を次もまた使える
                else chmin(DP[i+1][j], DP[i][j]+1), chmin(DP[i+1][j+1],DP[i][j]+1);
            }else{ //マーク マーク
                chmin(DP[i+1][j],DP[i][j]);
                chmin(DP[i][j+1],DP[i][j]);
                chmin(DP[i+1][j+1],DP[i][j]);
            }
        }
    }
    REP(i,N) chmin(DP[i+1][M],DP[i][M]+ (S_info[i]==0));
    REP(j,M) chmin(DP[N][j+1],DP[N][j]+ (T_info[j]==0));
    auto ans = DP.back().back();
    cout << ans << endl;
}