結果

問題 No.874 正規表現間距離
ユーザー parukiparuki
提出日時 2019-08-30 23:19:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,160 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 166,400 KB
実行使用メモリ 19,336 KB
最終ジャッジ日時 2023-08-14 08:14:47
合計ジャッジ時間 3,289 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 8 ms
11,840 KB
testcase_17 AC 9 ms
11,484 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 23 ms
19,240 KB
testcase_26 AC 20 ms
19,136 KB
testcase_27 AC 22 ms
19,316 KB
testcase_28 WA -
testcase_29 AC 24 ms
19,044 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = INT_MAX / 3;
string S, T;
int dp[2002][2002];

void solve() {
    cin >> S >> T;
    int N = sz(S), M = sz(T);
    S += 'c';
    T += 'd';
    
    rep(i, N + 1)rep(j, M + 1)dp[i][j] = INF;
    dp[0][0] = 0;

    rep(i, N+1)rep(j, M+1) {
        int x = dp[i][j];
        char a = S[i], b = T[j];
        if ((a == '*' || a == '?') && (b == '*'&&b == '?')) {
            smin(dp[i + 1][j], dp[i - 1][j]);
            smin(dp[i][j + 1], dp[i][j - 1]);
            smin(dp[i + 1][j], x);
            smin(dp[i][j + 1], x);
        } else if (a == '*') {
            if (S[i - 1] == b) {
                smin(dp[i][j + 1], x);
            }
            smin(dp[i + 1][j], x);
            smin(dp[i + 1][j], dp[i - 1][j]);
            smin(dp[i][j + 1], x + 1);
        } else if (a == '?') {
            smin(dp[i + 1][j], x);
            smin(dp[i + 1][j], dp[i - 1][j]);
        } else if (b == '*') {
            if (a == T[j - 1]) {
                smin(dp[i + 1][j], x);
            }
            smin(dp[i][j + 1], x);
            smin(dp[i][j + 1], dp[i][j - 1]);
            smin(dp[i + 1][j], x + 1);
        } else if (b == '?') {
            smin(dp[i][j + 1], x);
            smin(dp[i][j + 1], dp[i][j - 1]);
        } else {
            smin(dp[i + 1][j], x + 1);
            smin(dp[i][j + 1], x + 1);
            if (S[i] == T[j]) {
                smin(dp[i + 1][j + 1], x);
            }
        }
    }


    cout << dp[N][M] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0