結果
| 問題 |
No.1818 6 Operations
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-22 21:42:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 120 ms / 2,500 ms |
| コード長 | 1,086 bytes |
| コンパイル時間 | 2,727 ms |
| コンパイル使用メモリ | 201,244 KB |
| 最終ジャッジ日時 | 2025-01-28 01:28:36 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define bokusunny ios::sync_with_stdio(false), cin.tie(nullptr);
void solve() {
int N, M;
cin >> N >> M;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
vector<int> B(M);
for (int i = 0; i < M; i++) cin >> B[i];
vector<int> AA;
for (auto &a : A) {
AA.push_back(0);
for (int i = 0; i < a; i++) AA.push_back(1);
}
vector<int> BB;
for (auto &b : B) {
BB.push_back(0);
for (int i = 0; i < b; i++) BB.push_back(1);
}
const int INFINT = 1 << 30;
int sz_a = (int)AA.size();
int sz_b = (int)BB.size();
vector dp(sz_a + 1, vector<int>(sz_b + 1, INFINT));
dp[0][0] = 0;
for (int i = 0; i <= sz_a; i++) {
for (int j = 0; j <= sz_b; j++) {
if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
if (i > 0 && j > 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (int)(AA[i - 1] != BB[j - 1]));
}
}
}
cout << dp[sz_a][sz_b] << endl;
}
int main() {
bokusunny;
solve();
return 0;
}