結果

問題 No.874 正規表現間距離
ユーザー kimiyukikimiyuki
提出日時 2019-08-30 23:34:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,036 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 204,064 KB
実行使用メモリ 19,212 KB
最終ジャッジ日時 2023-08-14 08:46:41
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 9 ms
6,980 KB
testcase_17 AC 10 ms
7,024 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 33 ms
18,936 KB
testcase_26 AC 33 ms
19,172 KB
testcase_27 AC 67 ms
18,904 KB
testcase_28 WA -
testcase_29 AC 65 ms
18,948 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 1 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int solve(const string & a, const string & b) {
    auto dp = make_table(a.length() + 1, b.length() + 1, INT_MAX);
    dp[0][0] = 0;
    REP (i, a.size()) if (isalpha(a[i])) {
        REP (j, b.size()) if (isalpha(b[j])) {
            if (dp[i][j] == INT_MAX) continue;
            char a_op = (i + 1 < a.size() and not isalpha(a[i + 1]) ? a[i + 1] : '\0');
            char b_op = (j + 1 < b.size() and not isalpha(b[j + 1]) ? b[j + 1] : '\0');
            int ni = i + 1 + not not a_op;
            int nj = j + 1 + not not b_op;
            if (a[i] == b[j]) {
                chmin(dp[ni][nj], dp[i][j]);
                if (a_op == '*') chmin(dp[i][nj], dp[i][j]);
                if (b_op == '*') chmin(dp[ni][j], dp[i][j]);
            }
            if (a_op) chmin(dp[ni][j], dp[i][j]);
            if (b_op) chmin(dp[i][nj], dp[i][j]);
            chmin(dp[ni][j], dp[i][j] + 1);
            chmin(dp[i][nj], dp[i][j] + 1);
        }
    }
    REP (j, b.size()) if (isalpha(b[j])) {
        int i = a.size();
        char b_op = (j + 1 < b.size() and not isalpha(b[j + 1]) ? b[j + 1] : '\0');
        int nj = j + 1 + not not b_op;
        chmin(dp[i][nj], dp[i][j] + not b_op);
    }
    REP (i, a.size()) if (isalpha(a[i])) {
        int j = b.size();
        char a_op = (i + 1 < a.size() and not isalpha(a[i + 1]) ? a[i + 1] : '\0');
        int ni = i + 1 + not not a_op;
        chmin(dp[ni][j], dp[i][j] + not a_op);
    }
    return dp[a.size()][b.size()];
}

int main() {
    string a, b; cin >> a >> b;
    cout << solve(a, b) << endl;
    return 0;
}
0