結果

問題 No.1818 6 Operations
ユーザー nok0nok0
提出日時 2021-11-08 10:41:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,500 ms
コード長 692 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 203,956 KB
実行使用メモリ 59,864 KB
最終ジャッジ日時 2023-08-11 07:00:23
合計ジャッジ時間 4,667 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 26 ms
20,028 KB
testcase_09 AC 50 ms
35,480 KB
testcase_10 AC 27 ms
20,220 KB
testcase_11 AC 24 ms
18,964 KB
testcase_12 AC 40 ms
28,880 KB
testcase_13 AC 33 ms
24,124 KB
testcase_14 AC 37 ms
27,356 KB
testcase_15 AC 43 ms
31,300 KB
testcase_16 AC 36 ms
26,300 KB
testcase_17 AC 53 ms
37,940 KB
testcase_18 AC 75 ms
51,908 KB
testcase_19 AC 72 ms
50,080 KB
testcase_20 AC 76 ms
52,716 KB
testcase_21 AC 77 ms
53,484 KB
testcase_22 AC 66 ms
46,292 KB
testcase_23 AC 82 ms
56,648 KB
testcase_24 AC 69 ms
47,888 KB
testcase_25 AC 87 ms
59,864 KB
testcase_26 AC 69 ms
48,680 KB
testcase_27 AC 74 ms
51,056 KB
testcase_28 AC 27 ms
19,968 KB
testcase_29 AC 24 ms
18,848 KB
testcase_30 AC 74 ms
51,920 KB
testcase_31 AC 79 ms
55,292 KB
testcase_32 AC 82 ms
57,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	string as = "", bs = "";
	for(int i = 0; i < n; i++) {
		as.push_back('0');
		int a;
		cin >> a;
		while(a--) as.push_back('1');
	}
	for(int i = 0; i < m; i++) {
		bs.push_back('0');
		int b;
		cin >> b;
		while(b--) bs.push_back('1');
	}

	n = as.size(), m = bs.size();
	vector dp(n + 1, vector(m + 1, 0));
	for(int i = 0; i <= n; i++) dp[i][0] = i;
	for(int j = 0; j <= m; j++) dp[0][j] = j;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (as[i - 1] != bs[j - 1])});
		}
	}

	cout << dp.back().back() << '\n';
}
0