結果

問題 No.1767 BLUE to RED
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-16 16:39:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 108,404 KB
実行使用メモリ 4,832 KB
最終ジャッジ日時 2023-08-29 23:39:29
合計ジャッジ時間 5,076 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 93 ms
4,380 KB
testcase_10 AC 119 ms
4,384 KB
testcase_11 AC 101 ms
4,384 KB
testcase_12 AC 92 ms
4,384 KB
testcase_13 AC 132 ms
4,380 KB
testcase_14 AC 163 ms
4,572 KB
testcase_15 AC 162 ms
4,572 KB
testcase_16 AC 163 ms
4,832 KB
testcase_17 AC 162 ms
4,532 KB
testcase_18 AC 162 ms
4,688 KB
testcase_19 AC 163 ms
4,576 KB
testcase_20 AC 163 ms
4,692 KB
testcase_21 AC 163 ms
4,628 KB
testcase_22 AC 163 ms
4,556 KB
testcase_23 AC 163 ms
4,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    int N, M, ans=0, mi;
    cin >> N >> M;
    vector<int> A(N), B(M);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<M; i++) cin >> B[i];

    for (int i=0; i<N-1; i++){
        auto it1 = lower_bound(B.begin(), B.end(), A[i]);
        auto it2 = lower_bound(B.begin(), B.end(), A[i+1]);
        if (it2 == B.begin() || it1 == it2) continue;
        it2--;
        int l=it1-B.begin(), r=it2-B.begin();

        mi = 1e9;
        mi = min(mi, B[r]-A[i]);
        mi = min(mi, A[i+1]-B[l]);
        for (int j=l; j<r; j++) mi = min(mi, B[j]-A[i]+A[i+1]-B[j+1]);
        ans += mi;
    }

    ans += max(0, B[M-1] - A[N-1]);
    ans += max(0, A[0] - B[0]);

    cout << ans << endl;

    return 0;
}
0