結果

問題 No.1818 6 Operations
ユーザー bokusunnybokusunny
提出日時 2022-02-22 21:42:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,500 ms
コード長 1,086 bytes
コンパイル時間 3,844 ms
コンパイル使用メモリ 205,192 KB
実行使用メモリ 59,816 KB
最終ジャッジ日時 2023-09-13 12:36:47
合計ジャッジ時間 7,388 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 33 ms
19,964 KB
testcase_09 AC 63 ms
35,456 KB
testcase_10 AC 33 ms
20,108 KB
testcase_11 AC 31 ms
18,804 KB
testcase_12 AC 51 ms
28,860 KB
testcase_13 AC 41 ms
24,156 KB
testcase_14 AC 47 ms
27,500 KB
testcase_15 AC 54 ms
31,204 KB
testcase_16 AC 46 ms
26,448 KB
testcase_17 AC 67 ms
37,812 KB
testcase_18 AC 92 ms
52,132 KB
testcase_19 AC 88 ms
50,040 KB
testcase_20 AC 94 ms
52,692 KB
testcase_21 AC 96 ms
53,652 KB
testcase_22 AC 83 ms
46,520 KB
testcase_23 AC 102 ms
56,656 KB
testcase_24 AC 85 ms
47,924 KB
testcase_25 AC 107 ms
59,816 KB
testcase_26 AC 86 ms
48,724 KB
testcase_27 AC 91 ms
51,060 KB
testcase_28 AC 34 ms
20,192 KB
testcase_29 AC 31 ms
18,892 KB
testcase_30 AC 93 ms
51,864 KB
testcase_31 AC 98 ms
54,996 KB
testcase_32 AC 103 ms
57,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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