/*    ∫ ∫ ∫    ノヽ   (_  )  (_    ) (______ )  ヽ(´・ω・)ノ     |  /    UU */ #pragma region macro #include typedef long long int64; using namespace std; typedef vector vi; const int MOD = (int)1e9 + 7; const int64 INF = 1LL << 62; const int inf = 1<<30; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream& operator<<(ostream& os, const vector &V){ int N = V.size(); REP(i,N){ os << V[i]; if (i!=N-1) os << " "; } os << "\n"; return os; } template ostream& operator<<(ostream& os, pair const&P){ os << "("; os << P.first; os << " , "; os << P.second; os << ")"; return os; } template ostream& operator<<(ostream& os, set &S){ auto it=S.begin(); while(it!=S.end()){ os << *it; os << " "; it++; } os << "\n"; return os; } template ostream& operator<<(ostream& os, deque &q){ for(auto it=q.begin();it ostream& operator<<(ostream& os, map const&M){ for(auto e:M){ os<> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)}; #pragma endregion //fixed<> U >> V; string S="",T=""; vector 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> DP(N+1,vector(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; }