結果
問題 | No.874 正規表現間距離 |
ユーザー | はまやんはまやん |
提出日時 | 2019-08-31 10:40:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 4,661 bytes |
コンパイル時間 | 2,007 ms |
コンパイル使用メモリ | 209,772 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-11-24 05:10:37 |
合計ジャッジ時間 | 3,296 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 1 ms
5,248 KB |
testcase_15 | AC | 1 ms
5,248 KB |
testcase_16 | AC | 5 ms
6,656 KB |
testcase_17 | AC | 4 ms
6,656 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 11 ms
11,392 KB |
testcase_26 | AC | 9 ms
11,520 KB |
testcase_27 | AC | 31 ms
19,072 KB |
testcase_28 | AC | 30 ms
16,768 KB |
testcase_29 | AC | 33 ms
19,200 KB |
testcase_30 | AC | 34 ms
19,200 KB |
testcase_31 | AC | 34 ms
17,920 KB |
testcase_32 | AC | 33 ms
17,920 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 11 ms
10,752 KB |
testcase_37 | AC | 10 ms
10,624 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 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; }