結果

問題 No.2248 max(C)-min(C)
ユーザー lddlinanlddlinan
提出日時 2023-03-17 22:28:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 695 ms / 3,000 ms
コード長 1,793 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 96,588 KB
実行使用メモリ 35,496 KB
最終ジャッジ日時 2023-10-18 15:25:26
合計ジャッジ時間 17,509 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 459 ms
31,640 KB
testcase_19 AC 30 ms
6,932 KB
testcase_20 AC 558 ms
35,496 KB
testcase_21 AC 511 ms
33,968 KB
testcase_22 AC 343 ms
25,212 KB
testcase_23 AC 171 ms
16,932 KB
testcase_24 AC 49 ms
8,716 KB
testcase_25 AC 505 ms
32,668 KB
testcase_26 AC 444 ms
29,548 KB
testcase_27 AC 491 ms
32,412 KB
testcase_28 AC 23 ms
6,208 KB
testcase_29 AC 451 ms
30,424 KB
testcase_30 AC 130 ms
14,304 KB
testcase_31 AC 574 ms
35,496 KB
testcase_32 AC 64 ms
9,456 KB
testcase_33 AC 120 ms
13,080 KB
testcase_34 AC 584 ms
35,492 KB
testcase_35 AC 575 ms
35,496 KB
testcase_36 AC 553 ms
35,496 KB
testcase_37 AC 242 ms
19,844 KB
testcase_38 AC 482 ms
31,700 KB
testcase_39 AC 532 ms
31,676 KB
testcase_40 AC 506 ms
31,664 KB
testcase_41 AC 422 ms
28,224 KB
testcase_42 AC 493 ms
31,680 KB
testcase_43 AC 440 ms
28,940 KB
testcase_44 AC 508 ms
31,676 KB
testcase_45 AC 376 ms
26,312 KB
testcase_46 AC 164 ms
15,756 KB
testcase_47 AC 518 ms
31,676 KB
testcase_48 AC 226 ms
16,756 KB
testcase_49 AC 683 ms
35,484 KB
testcase_50 AC 680 ms
35,484 KB
testcase_51 AC 690 ms
35,484 KB
testcase_52 AC 695 ms
35,480 KB
testcase_53 AC 66 ms
8,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
typedef struct { int h, i; }RNode;
int as[200004];
int bs[200004];
int cs[200004];
class mypcmp {
public:
    bool operator()(const RNode& a, const RNode& b) {
        return a.h<b.h;
    }
};


#define INF 0x7fffffff
int main() {
    int n, i, h, mh, r, valid, t;
    scanf("%d", &n);
    for (i=0; i<n; i++) scanf("%d", &as[i]);
    for (i=0; i<n; i++) scanf("%d", &bs[i]);
    set<int> hs;
    for (i=0; i<n; i++) {
        if (as[i]>bs[i]) { t=as[i]; as[i]=bs[i]; bs[i]=t; }
        cs[i]=(as[i]+bs[i])/2;
        hs.insert(as[i]);
        hs.insert(bs[i]);
        hs.insert(cs[i]);
    }
    priority_queue<RNode, vector<RNode>, mypcmp> q;
    r = INF;
    mh= INF;
    for (i=0; i<n; i++) {
        q.push({bs[i], i});
        mh=min(mh, bs[i]);
    }
    for (auto it = hs.rbegin(); it!=hs.rend(); it++) {
        h = *it;
        valid=1;
        while(!q.empty()) {
            auto x = q.top();
            if (x.h>h) {
                q.pop();
                i=x.i;
                if (cs[i]<=h) {
                    q.push({cs[i], i});
                    mh = min(mh, cs[i]);
                } else if (as[i]<=h) {
                    q.push({as[i], i});
                    mh = min(mh, as[i]);
                } else {
                    valid=0;
                    break;
                }
            } else break;
        }
        if (valid==0) break;
        r = min(r, h-mh);
    }
    printf("%d\n", r);

    return 0;
}
0