結果

問題 No.874 正規表現間距離
ユーザー kimiyukikimiyuki
提出日時 2019-08-30 23:34:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,036 bytes
コンパイル時間 3,951 ms
コンパイル使用メモリ 206,392 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-05-01 21:19:00
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 10 ms
7,296 KB
testcase_17 AC 10 ms
7,168 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 35 ms
18,944 KB
testcase_26 AC 34 ms
18,944 KB
testcase_27 AC 68 ms
18,944 KB
testcase_28 WA -
testcase_29 AC 67 ms
18,944 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
5,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 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