結果

問題 No.874 正規表現間距離
ユーザー beetbeet
提出日時 2019-08-30 22:23:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,536 bytes
コンパイル時間 2,410 ms
コンパイル使用メモリ 203,828 KB
実行使用メモリ 35,488 KB
最終ジャッジ日時 2024-05-01 18:37:13
合計ジャッジ時間 4,744 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,328 KB
testcase_01 AC 11 ms
35,172 KB
testcase_02 AC 13 ms
35,200 KB
testcase_03 AC 12 ms
35,456 KB
testcase_04 AC 11 ms
35,200 KB
testcase_05 AC 12 ms
35,328 KB
testcase_06 AC 12 ms
35,328 KB
testcase_07 AC 13 ms
35,328 KB
testcase_08 AC 11 ms
35,200 KB
testcase_09 AC 12 ms
35,200 KB
testcase_10 AC 13 ms
35,328 KB
testcase_11 AC 12 ms
35,200 KB
testcase_12 AC 12 ms
35,320 KB
testcase_13 AC 12 ms
35,316 KB
testcase_14 AC 12 ms
35,328 KB
testcase_15 AC 12 ms
35,200 KB
testcase_16 AC 18 ms
35,448 KB
testcase_17 AC 18 ms
35,456 KB
testcase_18 AC 17 ms
35,328 KB
testcase_19 AC 11 ms
35,200 KB
testcase_20 WA -
testcase_21 AC 12 ms
35,328 KB
testcase_22 AC 11 ms
35,328 KB
testcase_23 AC 11 ms
35,328 KB
testcase_24 AC 12 ms
35,200 KB
testcase_25 AC 32 ms
35,200 KB
testcase_26 AC 33 ms
35,328 KB
testcase_27 AC 35 ms
35,452 KB
testcase_28 WA -
testcase_29 AC 38 ms
35,360 KB
testcase_30 AC 43 ms
35,328 KB
testcase_31 AC 44 ms
35,328 KB
testcase_32 AC 44 ms
35,344 KB
testcase_33 AC 11 ms
35,328 KB
testcase_34 AC 11 ms
35,212 KB
testcase_35 AC 11 ms
35,328 KB
testcase_36 AC 21 ms
35,328 KB
testcase_37 AC 20 ms
35,328 KB
testcase_38 AC 12 ms
35,328 KB
testcase_39 AC 12 ms
35,456 KB
testcase_40 AC 12 ms
35,200 KB
testcase_41 AC 13 ms
35,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0