結果

問題 No.874 正規表現間距離
ユーザー betrue12betrue12
提出日時 2019-08-30 23:03:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 169,232 KB
実行使用メモリ 19,104 KB
最終ジャッジ日時 2023-08-14 07:34:12
合計ジャッジ時間 3,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 4 ms
7,264 KB
testcase_17 AC 5 ms
7,116 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 12 ms
11,680 KB
testcase_26 AC 9 ms
11,576 KB
testcase_27 AC 21 ms
19,104 KB
testcase_28 AC 17 ms
17,708 KB
testcase_29 AC 23 ms
19,068 KB
testcase_30 AC 23 ms
19,072 KB
testcase_31 AC 19 ms
17,812 KB
testcase_32 AC 20 ms
17,748 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 8 ms
11,548 KB
testcase_37 AC 8 ms
11,568 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void chmin(int& a, int b){
    a = min(a, b);
}

int main(){
    vector<pair<char, char>> A[2];
    for(int t=0; t<2; t++){
        string s;
        cin >> s;
        s.push_back('!');
        s.push_back('!');
        for(int i=0; i<s.size()-1; i++){
            if(s[i+1] == '*'){
                A[t].emplace_back(s[i], '*');
                i++;
            }else if(s[i+1] == '?'){
                A[t].emplace_back(s[i], '?');
                i++;
            }else{
                A[t].emplace_back(s[i], ' ');
            }
        }
    }
    int N = A[0].size(), M = A[1].size();
    static int dp[2010][2010];
    for(int i=0; i<=N; i++) for(int j=0; j<=M; j++) dp[i][j] = 1e9;
    dp[0][0] = 0;
    for(int i=0; i<N; i++) for(int j=0; j<M; j++){
        chmin(dp[i+1][j], dp[i][j] + (A[0][i].second == ' '));
        chmin(dp[i][j+1], dp[i][j] + (A[1][j].second == ' '));
        chmin(dp[i+1][j+1], dp[i][j] + (A[0][i].first != A[1][j].first));
        if(A[0][i].first == A[1][j].first){
            if(A[1][j].second == '*') chmin(dp[i+1][j], dp[i][j]);
            if(A[0][i].second == '*') chmin(dp[i][j+1], dp[i][j]);
        }
    }
    cout << dp[N][M] << endl;
    return 0;
}
0