結果

問題 No.1767 BLUE to RED
ユーザー first_vilfirst_vil
提出日時 2021-10-12 23:15:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 790 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 203,960 KB
実行使用メモリ 10,500 KB
最終ジャッジ日時 2023-09-12 04:42:22
合計ジャッジ時間 8,006 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 89 ms
5,940 KB
testcase_10 AC 115 ms
8,488 KB
testcase_11 AC 96 ms
6,144 KB
testcase_12 AC 88 ms
5,980 KB
testcase_13 AC 125 ms
8,772 KB
testcase_14 AC 156 ms
9,504 KB
testcase_15 AC 156 ms
9,536 KB
testcase_16 AC 155 ms
9,260 KB
testcase_17 AC 155 ms
9,016 KB
testcase_18 AC 156 ms
10,500 KB
testcase_19 AC 154 ms
9,348 KB
testcase_20 AC 156 ms
10,032 KB
testcase_21 AC 156 ms
9,428 KB
testcase_22 AC 156 ms
9,172 KB
testcase_23 AC 155 ms
10,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n), b(m);
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];
    vector<pair<int, bool>> x;
    for (int i = 0, j = 0; i < n || j < m;) {
        if (j == m || (i < n && a[i] < b[j])) {
            x.emplace_back(a[i++], true);
        }
        else {
            x.emplace_back(b[j++], false);
        }
    }

    int ans = x.back().first - x.front().first;
    int pre = -1, mac = 0;
    rep(i,n + m) {
        if (i) {
            mac = max(mac, x[i].first - x[i - 1].first);
        }
        if (x[i].second) {
            if (pre != -1)ans -= mac;
            pre = i, mac = 0;
        }
    }
    cout << ans << "\n";
    
    return 0;
}
0