結果

問題 No.1767 BLUE to RED
ユーザー tnakao0123tnakao0123
提出日時 2021-11-30 10:00:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 41,604 KB
実行使用メモリ 4,544 KB
最終ジャッジ日時 2023-09-16 01:34:27
合計ジャッジ時間 4,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 32 ms
4,376 KB
testcase_10 AC 41 ms
4,380 KB
testcase_11 AC 33 ms
4,376 KB
testcase_12 AC 32 ms
4,380 KB
testcase_13 AC 43 ms
4,376 KB
testcase_14 AC 54 ms
4,520 KB
testcase_15 AC 54 ms
4,528 KB
testcase_16 AC 55 ms
4,436 KB
testcase_17 AC 54 ms
4,512 KB
testcase_18 AC 55 ms
4,496 KB
testcase_19 AC 54 ms
4,492 KB
testcase_20 AC 54 ms
4,524 KB
testcase_21 AC 53 ms
4,508 KB
testcase_22 AC 56 ms
4,544 KB
testcase_23 AC 55 ms
4,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1767.cc:  No.1767 BLUE to RED - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int INF = (1U << 31) - 1;
const int MINF = -(1 << 30);

/* typedef */

/* global variables */

int as[MAX_N + 2], bs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= n; i++) scanf("%d", as + i);
  as[0] = MINF, as[n + 1] = INF;
  n += 2;

  for (int i = 0; i < m; i++) scanf("%d", bs + i);

  int sum = 0;
  for (int i = 0, k = 0; i < m;) {
    while (as[k + 1] < bs[i]) k++;

    int j = i + 1;
    while (j < m && bs[j] < as[k + 1]) j++;

    int mind = INF;
    for (int l = i; l <= j; l++) {
      int d = 0;
      if (l > i) d += bs[l - 1] - as[k];
      if (l < j) d += as[k + 1] - bs[l];
      mind = min(mind, d);
    }

    sum += mind;

    i = j;
  }

  printf("%d\n", sum);
  return 0;
}
0