結果

問題 No.874 正規表現間距離
ユーザー pekempeypekempey
提出日時 2019-08-30 22:55:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 171,020 KB
実行使用メモリ 18,948 KB
最終ジャッジ日時 2023-08-14 07:08:07
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,388 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 13 ms
6,972 KB
testcase_17 AC 13 ms
6,912 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 47 ms
18,948 KB
testcase_26 AC 46 ms
18,904 KB
testcase_27 AC 46 ms
18,852 KB
testcase_28 AC 47 ms
18,776 KB
testcase_29 AC 45 ms
18,824 KB
testcase_30 AC 45 ms
18,848 KB
testcase_31 AC 48 ms
18,852 KB
testcase_32 AC 48 ms
18,896 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 13 ms
7,116 KB
testcase_37 AC 13 ms
6,968 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

void chmin(int &x, int y) {
  x = min(x, y);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string A, B; cin >> A >> B;
  const int N = A.size();
  const int M = B.size();
  A += "$$";
  B += "$$";
  vector<vector<int>> dp(N + 3, vector<int>(M + 3, 1e9));
  dp[0][0] = 0;
  rep(i, N+1) rep(j, M+1) {
    chmin(dp[i+1][j], dp[i][j] + 1);
    chmin(dp[i][j+1], dp[i][j] + 1);
    if (A[i] == '*' || A[i] == '?' || A[i + 1] == '*' || A[i + 1] == '?') chmin(dp[i+1][j], dp[i][j]);
    if (B[j] == '*' || B[j] == '?' || B[j + 1] == '*' || B[j + 1] == '?') chmin(dp[i][j+1], dp[i][j]);
    char x = A[i] == '*' ? A[i - 1] : A[i];
    char y = B[j] == '*' ? B[j - 1] : B[j];
    chmin(dp[i + (A[i] != '*')][j + (B[j] != '*')], dp[i][j] + (x != y));
  }
  cout << dp[N][M] << endl;
}
0