結果

問題 No.1767 BLUE to RED
ユーザー penguinshunyapenguinshunya
提出日時 2021-11-26 23:43:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 201,860 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-09-12 05:39:36
合計ジャッジ時間 5,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 99 ms
4,840 KB
testcase_10 AC 128 ms
5,416 KB
testcase_11 AC 107 ms
4,940 KB
testcase_12 AC 98 ms
4,992 KB
testcase_13 AC 142 ms
5,716 KB
testcase_14 AC 174 ms
6,324 KB
testcase_15 AC 174 ms
6,248 KB
testcase_16 AC 175 ms
6,160 KB
testcase_17 AC 174 ms
6,296 KB
testcase_18 AC 174 ms
6,268 KB
testcase_19 AC 175 ms
6,504 KB
testcase_20 AC 174 ms
6,164 KB
testcase_21 AC 174 ms
6,244 KB
testcase_22 AC 174 ms
6,160 KB
testcase_23 AC 175 ms
6,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  long long ans = 0;
  for (int i = 0; i + 1 < n; i++) {
    int bl = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
    int br = upper_bound(b.begin(), b.end(), a[i + 1]) - b.begin();
    if (bl == br) {
      continue;
    }
    long long mi = 0;
    mi = max(mi, b[bl] - a[i] - 1);
    mi = max(mi, a[i + 1] - b[br - 1] - 1);
    for (int j = bl; j + 1 < br; j++) {
      mi = max(mi, b[j + 1] - b[j] - 1);
    }
    ans += a[i + 1] - a[i] - 1 - mi;
  }
  {
    auto it = lower_bound(b.begin(), b.end(), a[0]);
    if (it != b.begin()) {
      ans += a[0] - b[0];
    }
  }
  {
    auto it = lower_bound(b.begin(), b.end(), a[n - 1]);
    if (it != b.end()) {
      ans += b[m - 1] - a[n - 1];
    }
  }
  cout << ans << endl;
  return 0;
}
0