結果

問題 No.1767 BLUE to RED
ユーザー gazelle
提出日時 2021-11-26 22:56:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,504 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 195,072 KB
最終ジャッジ日時 2025-01-26 01:41:46
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i, n, m) for(long long i = (n); i < (long long)(m); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr ld eps = 1e-6;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
    REP(i, v.size()) {
        if(i)
            os << " ";
        os << v[i];
    }
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    vector<ll> a(n + 2), b(m);
    a[0] = -inf * inf;
    a[n + 1] = inf * inf;
    REP(i, n) cin >> a[1 + i];
    REP(i, m) cin >> b[i];

    n += 2;
    ll ans = 0;

    REP(i, n - 1) {
        // cout << i << endl;
        ll diff = a[i + 1] - a[i] - 1;
        auto iter = lower_bound(ALL(b), a[i]);
        ll max_jump = 0, prev = a[i];
        while(iter != b.end() && *iter < a[i + 1]) {
            max_jump = max(max_jump, *iter - prev - 1);
            prev = *iter;
            iter += 1;
        }
        max_jump = max(max_jump, a[i + 1] - prev - 1);
        // cout << i << " " << diff << " " << max_jump << endl;

        ans += diff - max_jump;
    }

    cout << ans << endl;

    return 0;
}
0