結果

問題 No.874 正規表現間距離
ユーザー pekempeypekempey
提出日時 2019-08-30 22:44:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 170,420 KB
実行使用メモリ 19,096 KB
最終ジャッジ日時 2023-08-14 06:40:34
合計ジャッジ時間 3,568 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 15 ms
6,968 KB
testcase_17 AC 15 ms
6,940 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 60 ms
19,096 KB
testcase_26 AC 54 ms
18,840 KB
testcase_27 AC 56 ms
18,816 KB
testcase_28 AC 58 ms
18,932 KB
testcase_29 AC 56 ms
18,820 KB
testcase_30 AC 56 ms
18,940 KB
testcase_31 AC 57 ms
18,836 KB
testcase_32 AC 57 ms
18,820 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 16 ms
6,940 KB
testcase_37 AC 16 ms
7,004 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 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();
  vector<vector<int>> dp(N + 1, vector<int>(M + 1, 1e9));
  dp[0][0] = 0;
  rep(i, N+1) rep(j, M+1) {
    if (i < N && (A[i] == '*' || A[i] == '?')) chmin(dp[i+1][j], dp[i][j]);
    if (j < M && (B[j] == '*' || B[j] == '?')) chmin(dp[i][j+1], dp[i][j]);
    if (i + 1 < N && (A[i + 1] == '*' || A[i + 1] == '?')) chmin(dp[i+1][j], dp[i][j]);
    if (j + 1 < M && (B[j + 1] == '*' || B[j + 1] == '?')) chmin(dp[i][j+1], dp[i][j]);
    if (i < N) chmin(dp[i+1][j], dp[i][j] + 1);
    if (j < M) chmin(dp[i][j+1], dp[i][j] + 1);
    if (i < N && j < M && A[i] != '?' && B[j] != '?') {
      char x = A[i] == '*' ? A[i - 1] : A[i];
      char y = B[j] == '*' ? B[j - 1] : B[j];
      if (A[i] == '*' && B[j] == '*') {
      } else if (A[i] == '*') {
        chmin(dp[i][j+1], dp[i][j] + (x != y));
      } else if (B[j] == '*') {
        chmin(dp[i+1][j], dp[i][j] + (x != y));
      } else {
        chmin(dp[i+1][j+1], dp[i][j] + (x != y));
      }
    }
  }
  cout << dp[N][M] << endl;
}
0