結果

問題 No.1767 BLUE to RED
ユーザー se1ka2se1ka2
提出日時 2021-11-26 22:41:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 72,416 KB
実行使用メモリ 12,768 KB
最終ジャッジ日時 2023-09-12 05:16:51
合計ジャッジ時間 4,885 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,644 KB
testcase_01 AC 4 ms
9,844 KB
testcase_02 AC 4 ms
9,608 KB
testcase_03 AC 4 ms
9,644 KB
testcase_04 AC 4 ms
9,632 KB
testcase_05 AC 4 ms
9,720 KB
testcase_06 AC 4 ms
9,584 KB
testcase_07 AC 4 ms
9,860 KB
testcase_08 AC 5 ms
9,776 KB
testcase_09 AC 110 ms
11,304 KB
testcase_10 AC 139 ms
11,828 KB
testcase_11 AC 113 ms
11,812 KB
testcase_12 AC 111 ms
11,380 KB
testcase_13 AC 160 ms
11,696 KB
testcase_14 AC 208 ms
12,720 KB
testcase_15 AC 207 ms
12,712 KB
testcase_16 AC 208 ms
12,736 KB
testcase_17 AC 206 ms
12,732 KB
testcase_18 AC 205 ms
12,692 KB
testcase_19 AC 206 ms
12,704 KB
testcase_20 AC 206 ms
12,700 KB
testcase_21 AC 205 ms
12,712 KB
testcase_22 AC 207 ms
12,744 KB
testcase_23 AC 205 ms
12,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

const ll INF = 100000000000;

ll dp[200002][2];

int main()
{
    int n, m;
    cin >> n >> m;
    P p[400002];
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        p[i] = P(a, 0);
    }
    for(int i = 0; i < m; i++){
        ll b;
        cin >> b;
        p[i + n] = P(b, 1);
    }
    p[n + m] = P(-INF, 0);
    sort(p, p + n + m + 1);
    int c = 0;
    for(int i = 1; i <= n + m; i++){
        if(p[i].second){
            c++;
            dp[c][0] = dp[c - 1][0] + p[i].first - p[i - 1].first;
            dp[c][1] = min(dp[c - 1][1] + p[i].first - p[i - 1].first, dp[c - 1][0]);
        }
        else{
            dp[c][0] = min(dp[c][0], dp[c][1] + p[i].first - p[i - 1].first);
            dp[c][1] = dp[c][0];
        }
    }
    cout << dp[c][0] << endl;
}
0