結果
問題 | No.874 正規表現間距離 |
ユーザー | tac |
提出日時 | 2019-09-03 16:38:02 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 2,730 bytes |
コンパイル時間 | 1,632 ms |
コンパイル使用メモリ | 170,200 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-06-06 14:00:46 |
合計ジャッジ時間 | 3,534 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
18,944 KB |
testcase_01 | AC | 10 ms
18,944 KB |
testcase_02 | AC | 10 ms
18,944 KB |
testcase_03 | AC | 11 ms
18,944 KB |
testcase_04 | AC | 11 ms
19,072 KB |
testcase_05 | AC | 11 ms
19,072 KB |
testcase_06 | AC | 10 ms
19,072 KB |
testcase_07 | AC | 10 ms
18,944 KB |
testcase_08 | AC | 10 ms
19,072 KB |
testcase_09 | AC | 12 ms
18,944 KB |
testcase_10 | AC | 12 ms
18,944 KB |
testcase_11 | AC | 12 ms
18,944 KB |
testcase_12 | AC | 12 ms
19,072 KB |
testcase_13 | AC | 12 ms
19,072 KB |
testcase_14 | AC | 11 ms
18,944 KB |
testcase_15 | AC | 11 ms
18,944 KB |
testcase_16 | AC | 15 ms
18,944 KB |
testcase_17 | AC | 14 ms
18,944 KB |
testcase_18 | AC | 11 ms
18,944 KB |
testcase_19 | AC | 10 ms
19,072 KB |
testcase_20 | AC | 10 ms
19,072 KB |
testcase_21 | AC | 10 ms
18,944 KB |
testcase_22 | AC | 10 ms
18,944 KB |
testcase_23 | AC | 10 ms
19,200 KB |
testcase_24 | AC | 10 ms
19,072 KB |
testcase_25 | AC | 24 ms
19,200 KB |
testcase_26 | AC | 23 ms
19,200 KB |
testcase_27 | AC | 24 ms
19,072 KB |
testcase_28 | AC | 31 ms
19,072 KB |
testcase_29 | AC | 26 ms
19,200 KB |
testcase_30 | AC | 30 ms
18,944 KB |
testcase_31 | AC | 33 ms
19,200 KB |
testcase_32 | AC | 33 ms
19,200 KB |
testcase_33 | AC | 11 ms
18,944 KB |
testcase_34 | AC | 10 ms
18,944 KB |
testcase_35 | AC | 10 ms
18,944 KB |
testcase_36 | AC | 16 ms
19,072 KB |
testcase_37 | AC | 16 ms
19,072 KB |
testcase_38 | AC | 11 ms
18,944 KB |
testcase_39 | AC | 10 ms
19,072 KB |
testcase_40 | AC | 10 ms
18,944 KB |
testcase_41 | AC | 10 ms
18,944 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #define inf (int)(1e9+7) #define abs(x) (x >= 0 ? x : -(x)) #define ceil(a, b) a / b + !!(a % b) template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } int dp[2002][2002]; int main() { string s1, s2; cin >> s1 >> s2; rep(i, sz(s1)) if (s1[i] == '?' || s1[i] == '*') swap(s1[i], s1[i - 1]); rep(i, sz(s2)) if (s2[i] == '?' || s2[i] == '*') swap(s2[i], s2[i - 1]); // cout << s1 << " " << s2 << endl; fill_n(*dp, 2002 * 2002, inf); dp[0][0] = 0; rep(i, sz(s1) + 1) rep(j, sz(s2) + 1) { int a = 0, b = 0; if (s1[i] == '?') a = 1; else if (s1[i] == '*') a = 2; if (s2[j] == '?') b = 1; else if (s2[j] == '*') b = 2; if (a == 0 && b == 0) { /* 1 */ chmin(dp[i + 1][j], dp[i][j] + 1); /* 2 */ chmin(dp[i][j + 1], dp[i][j] + 1); /* 3 */ chmin(dp[i + 1][j + 1], dp[i][j] + (s1[i] != s2[j])); } else if (a == 1 && b == 0) { /* 1 */ chmin(dp[i + 2][j], dp[i][j]); /* 2 */ chmin(dp[i][j + 1], dp[i][j] + 1); /* 3 */ chmin(dp[i + 2][j + 1], dp[i][j] + (s1[i + 1] != s2[j])); } else if (a == 0 && b == 1) { // 双対 chmin(dp[i][j + 2], dp[i][j]); chmin(dp[i + 1][j], dp[i][j] + 1); chmin(dp[i + 1][j + 2], dp[i][j] + (s1[i] != s2[j + 1])); } else if (a == 2 && b == 0) { chmin(dp[i + 2][j], dp[i][j]); chmin(dp[i][j + 1], dp[i][j] + 1); chmin(dp[i][j + 1], dp[i][j] + (s1[i + 1] != s2[j])); chmin(dp[i + 2][j + 1], dp[i][j] + 1); } else if (a == 0 && b == 2) { // 双対 chmin(dp[i][j + 2], dp[i][j]); chmin(dp[i + 1][j], dp[i][j] + 1); chmin(dp[i + 1][j], dp[i][j] + (s1[i] != s2[j + 1])); chmin(dp[i + 1][j + 2], dp[i][j] + 1); } else { chmin(dp[i + 2][j], dp[i][j]); chmin(dp[i][j + 2], dp[i][j]); } } cout << dp[sz(s1)][sz(s2)] << endl; // rep(i, sz(s1) + 1) { rep(j, sz(s2) + 1) cout << dp[i][j] << " "; cout << endl; } }