結果

問題 No.1767 BLUE to RED
ユーザー yasuwoyasuwo
提出日時 2021-11-26 23:41:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,668 bytes
コンパイル時間 5,758 ms
コンパイル使用メモリ 307,356 KB
実行使用メモリ 6,288 KB
最終ジャッジ日時 2023-09-12 05:39:02
合計ジャッジ時間 8,028 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 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 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 39 ms
4,888 KB
testcase_10 AC 50 ms
5,416 KB
testcase_11 AC 41 ms
4,924 KB
testcase_12 AC 38 ms
4,880 KB
testcase_13 AC 55 ms
5,724 KB
testcase_14 AC 67 ms
6,244 KB
testcase_15 AC 67 ms
6,204 KB
testcase_16 AC 67 ms
6,200 KB
testcase_17 AC 67 ms
6,208 KB
testcase_18 AC 67 ms
6,288 KB
testcase_19 AC 67 ms
6,204 KB
testcase_20 AC 67 ms
6,192 KB
testcase_21 AC 67 ms
6,232 KB
testcase_22 AC 67 ms
6,236 KB
testcase_23 AC 67 ms
6,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
#include <atcoder/all>
// #include "library/templates/template.cpp"
using namespace atcoder;
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

long long solve(int N, int M, const std::vector<long long> &A, const std::vector<long long> &B)
{
    // ... solve
    ll ans = 0;
    int j = 0;
    if (A[0] > B[0])
    {
        ans += A[0] - B[0];
        while (j < M && B[j] < A[0])
        {
            j++;
        }
    }
    for (int i = 0; i + 1 < N; i++)
    {
        // A[i]...A[i+1]の間にあるB
        vector<ll> D;
        D.push_back(A[i]);
        while (j < M && B[j] < A[i + 1])
        {
            D.push_back(B[j]);
            j++;
        }
        D.push_back(A[i + 1]);
        if (D.size() > 2)
        {
            ll mindiff = 0;
            for (int t = 0; t + 1 < D.size(); t++)
            {
                mindiff = max(mindiff, D[t + 1] - D[t] - 1);
            }

            ans += A[i + 1] - A[i] - 1 - mindiff;
        }
    }
    if (A[N - 1] < B[M - 1])
    {
        ans += B[M - 1] - A[N - 1];
    }
    return ans;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int N, M;
    std::cin >> N;
    std::vector<long long> A(N);
    std::cin >> M;
    std::vector<long long> B(M);
    for (int i = 0; i < N; ++i)
    {
        std::cin >> A[i];
    }
    for (int i = 0; i < M; ++i)
    {
        std::cin >> B[i];
    }
    auto ans = solve(N, M, A, B);
    std::cout << ans << '\n';
    return 0;
}
0