結果

問題 No.874 正規表現間距離
ユーザー QCFiumQCFium
提出日時 2019-08-30 23:02:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,413 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 172,168 KB
実行使用メモリ 19,016 KB
最終ジャッジ日時 2023-08-14 07:30:21
合計ジャッジ時間 3,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 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,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 4 ms
4,728 KB
testcase_17 AC 5 ms
4,724 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 14 ms
8,672 KB
testcase_26 AC 13 ms
8,676 KB
testcase_27 AC 47 ms
18,952 KB
testcase_28 AC 28 ms
14,416 KB
testcase_29 AC 49 ms
19,016 KB
testcase_30 AC 51 ms
18,892 KB
testcase_31 AC 45 ms
16,200 KB
testcase_32 AC 45 ms
16,256 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 10 ms
6,864 KB
testcase_37 AC 11 ms
6,996 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/vector:64,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/queue:61,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:86,
         次から読み込み:  main.cpp:1:
メンバ関数 ‘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:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_vector.h:1124:32: 警告: ‘*(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);
      |                  ~~~~~~~~~~~~~~^~~~~~~~

ソースコード

diff #

#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;
}
0