結果

問題 No.1818 6 Operations
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-03-31 18:58:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,500 ms
コード長 785 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 208,560 KB
実行使用メモリ 116,608 KB
最終ジャッジ日時 2024-03-31 18:58:38
合計ジャッジ時間 5,573 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 36 ms
37,120 KB
testcase_09 AC 68 ms
68,224 KB
testcase_10 AC 38 ms
37,504 KB
testcase_11 AC 34 ms
34,816 KB
testcase_12 AC 54 ms
54,784 KB
testcase_13 AC 44 ms
45,440 KB
testcase_14 AC 51 ms
51,840 KB
testcase_15 AC 59 ms
59,648 KB
testcase_16 AC 49 ms
50,048 KB
testcase_17 AC 72 ms
72,960 KB
testcase_18 AC 100 ms
101,120 KB
testcase_19 AC 96 ms
97,152 KB
testcase_20 AC 102 ms
102,528 KB
testcase_21 AC 103 ms
104,192 KB
testcase_22 AC 88 ms
89,984 KB
testcase_23 AC 111 ms
110,464 KB
testcase_24 AC 98 ms
92,800 KB
testcase_25 AC 116 ms
116,608 KB
testcase_26 AC 94 ms
94,720 KB
testcase_27 AC 99 ms
99,072 KB
testcase_28 AC 37 ms
37,376 KB
testcase_29 AC 34 ms
34,944 KB
testcase_30 AC 101 ms
100,736 KB
testcase_31 AC 106 ms
107,136 KB
testcase_32 AC 112 ms
112,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;using ll = long long;
ll INF = (1LL << 60);
int main() {
	int n, m;cin >> n >> m;
	vector<int> A, B;
	for (int i = 0;i < n;i++) {
		int a;cin >> a;
		A.push_back(0);
		for (int j = 0;j < a;j++) A.push_back(1);
	}
	for (int i = 0;i < m;i++) {
		int b;cin >> b;
		B.push_back(0);
		for (int j = 0;j < b;j++) B.push_back(1);
	}
	int N = A.size();int M = B.size();
	vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, INF));
	dp[0][0] = 0;
	for (int i = 1;i <= N;i++) dp[i][0] = i;
	for (int i = 1;i  <= M;i++) dp[0][i] = i;
	for (int i = 1;i <= N;i++) for(int j = 1;j <= M;j++) {
		dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (A[i - 1] != B[j - 1]));
		dp[i][j] = min(dp[i][j], min(dp[i - 1][j], dp[i][j - 1]) + 1);
	}
	cout << dp[N][M] << endl;
}
0