結果

問題 No.1767 BLUE to RED
ユーザー SSRSSSRS
提出日時 2021-11-26 22:41:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 890 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 171,540 KB
実行使用メモリ 12,532 KB
最終ジャッジ日時 2023-09-12 05:17:19
合計ジャッジ時間 5,554 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 99 ms
8,436 KB
testcase_10 AC 126 ms
10,368 KB
testcase_11 AC 108 ms
8,684 KB
testcase_12 AC 100 ms
8,424 KB
testcase_13 AC 137 ms
11,172 KB
testcase_14 AC 173 ms
12,472 KB
testcase_15 AC 173 ms
12,448 KB
testcase_16 AC 173 ms
12,472 KB
testcase_17 AC 172 ms
12,404 KB
testcase_18 AC 174 ms
12,524 KB
testcase_19 AC 174 ms
12,480 KB
testcase_20 AC 173 ms
12,532 KB
testcase_21 AC 174 ms
12,512 KB
testcase_22 AC 173 ms
12,484 KB
testcase_23 AC 173 ms
12,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  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<vector<int>> C(N + 1);
  for (int i = 0; i < M; i++){
    int p = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    C[p].push_back(B[i]);
  }
  int ans = 0;
  if (!C[0].empty()){
    ans += A[0] - C[0][0];
  }
  if (!C[N].empty()){
    ans += C[N][C[N].size() - 1] - A[N - 1];
  }
  for (int i = 1; i < N; i++){
    if (!C[i].empty()){
      int cnt = C[i].size();
      int D = A[i] - A[i - 1];
      int mx = 0;
      mx = max(mx, C[i][0] - A[i - 1]);
      mx = max(mx, A[i] - C[i][cnt - 1]);
      for (int j = 0; j < cnt - 1; j++){
        mx = max(mx, C[i][j + 1] - C[i][j]);
      }
      ans += D - mx;
    }
  }
  cout << ans << endl;
}
0