結果
問題 | No.874 正規表現間距離 |
ユーザー | QCFium |
提出日時 | 2019-08-30 23:02:29 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,413 bytes |
コンパイル時間 | 1,654 ms |
コンパイル使用メモリ | 174,164 KB |
実行使用メモリ | 18,944 KB |
最終ジャッジ日時 | 2024-11-22 02:30:37 |
合計ジャッジ時間 | 3,185 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 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 | 2 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 | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 1 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 5 ms
5,248 KB |
testcase_17 | AC | 6 ms
5,248 KB |
testcase_18 | AC | 1 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 | 1 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 16 ms
8,704 KB |
testcase_26 | AC | 15 ms
8,704 KB |
testcase_27 | AC | 51 ms
18,944 KB |
testcase_28 | AC | 32 ms
14,592 KB |
testcase_29 | AC | 54 ms
18,944 KB |
testcase_30 | AC | 54 ms
18,944 KB |
testcase_31 | AC | 50 ms
16,256 KB |
testcase_32 | AC | 50 ms
16,256 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 | 12 ms
7,040 KB |
testcase_37 | AC | 12 ms
6,912 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 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:64, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/queue:61, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:86, from main.cpp:1: In member function 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>]', inlined from 'int main()' at main.cpp:31:9: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:1124:32: warning: '*(std::vector<int, std::allocator<int> >*)dp.std::vector<int>::<anonymous>.std::_Vector_base<int, std::allocator<int> >::_M_impl.std::_Vector_base<int, std::allocator<int> >::_Vector_impl::<anonymous>.std::_Vector_base<int, std::allocator<int> >::_Vector_impl_data::_M_start' may be used uninitialized [-Wmaybe-uninitialized] 1124 | return *(this->_M_impl._M_start + __n); | ~~~~~~~~~~~~~~^~~~~~~~
ソースコード
#include <bits/stdc++.h> int ri() { int n; assert(scanf("%d", &n) == 1); return n; } struct D { int c; bool one_more; bool more; }; int main () { std::string a_, b_; std::cin >> a_ >> b_; std::vector<D> a, b; for (auto c : a_) { if (c == '*') a.back().more = true; else if (c == '?') a.back().one_more = true; else a.push_back({c - 'a', false, false}); } for (auto c : b_) { if (c == '*') b.back().more = true; else if (c == '?') b.back().one_more = true; else b.push_back({c - 'a', false, false}); } int n = a.size(); int m = b.size(); std::vector<int> dp[n + 1]; for (int i = 0; i <= n; i++) dp[i].resize(m + 1, 1000000000); dp[0][0] = 0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (i < n && j < m) { int a_add = !a[i].more; int b_add = !b[j].more; int cost = a[i].c != b[j].c; dp[i + a_add][j + b_add] = std::min(dp[i + a_add][j + b_add], dp[i][j] + cost); } if (i < n) { int cost = 1; if (a[i].one_more || a[i].more) cost = 0; else if (j < m && b[j].c == a[i].c && b[j].more) cost = 0; dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + cost); } if (j < m) { int cost = 1; if (b[j].one_more || b[j].more) cost = 0; else if (i < n && a[i].c == b[j].c && a[i].more) cost = 0; dp[i][j + 1] = std::min(dp[i][j + 1], dp[i][j] + cost); } } } std::cout << dp[n][m] << std::endl; return 0; }