結果
問題 | No.874 正規表現間距離 |
ユーザー | はまやんはまやん |
提出日時 | 2019-08-31 10:40:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 4,661 bytes |
コンパイル時間 | 2,631 ms |
コンパイル使用メモリ | 208,892 KB |
実行使用メモリ | 19,072 KB |
最終ジャッジ日時 | 2024-05-03 07:15:08 |
合計ジャッジ時間 | 4,103 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
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 | AC | 2 ms
5,376 KB |
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 | 6 ms
6,656 KB |
testcase_17 | AC | 6 ms
6,656 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 | 17 ms
11,264 KB |
testcase_26 | AC | 14 ms
11,264 KB |
testcase_27 | AC | 41 ms
19,072 KB |
testcase_28 | AC | 37 ms
16,768 KB |
testcase_29 | AC | 41 ms
19,072 KB |
testcase_30 | AC | 43 ms
19,072 KB |
testcase_31 | AC | 41 ms
17,792 KB |
testcase_32 | AC | 42 ms
17,792 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 14 ms
10,752 KB |
testcase_37 | AC | 14 ms
10,496 KB |
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 |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i @hamayanhamayan / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ string A, B; //--------------------------------------------------------------------------------------------------- enum { NORMAL, QUESTION, STAR }; //--------------------------------------------------------------------------------------------------- vector<pair<int,char>> parse(string s) { int n = s.length(); vector<pair<int,char>> res; rep(i, 0, n) { if(i + 1 < n and s[i + 1] == '?') { res.push_back({QUESTION, s[i]}); i++; } else if(i + 1 < n and s[i + 1] == '*') { res.push_back({STAR, s[i]}); i++; } else res.push_back({NORMAL, s[i]}); } return res; } //--------------------------------------------------------------------------------------------------- int dp[2010][2010]; void _main() { cin >> A >> B; auto AA = parse(A); auto BB = parse(B); int NA = AA.size(); int NB = BB.size(); rep(a, 0, NA + 1) rep(b, 0, NB + 1) dp[a][b] = inf; dp[0][0] = 0; rep(a, 0, NA) rep(b, 0, NB) { if (AA[a].first == NORMAL) chmin(dp[a + 1][b], dp[a][b] + 1); else chmin(dp[a + 1][b], dp[a][b]); if (BB[b].first == NORMAL) chmin(dp[a][b + 1], dp[a][b] + 1); else chmin(dp[a][b + 1], dp[a][b]); if(AA[a].first == NORMAL and BB[b].first == NORMAL) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == NORMAL and BB[b].first == QUESTION) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == NORMAL and BB[b].first == STAR) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a + 1][b], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == QUESTION and BB[b].first == NORMAL) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == QUESTION and BB[b].first == QUESTION) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == QUESTION and BB[b].first == STAR) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a + 1][b], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == STAR and BB[b].first == NORMAL) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == STAR and BB[b].first == QUESTION) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == STAR and BB[b].first == STAR) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a + 1][b], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } } rep(a, 0, NA) { if (AA[a].first == NORMAL) chmin(dp[a + 1][NB], dp[a][NB] + 1); else chmin(dp[a + 1][NB], dp[a][NB]); } rep(b, 0, NB) { if (BB[b].first == NORMAL) chmin(dp[NA][b + 1], dp[NA][b] + 1); else chmin(dp[NA][b + 1], dp[NA][b]); } cout << dp[NA][NB] << endl; }