結果

問題 No.1460 Max of Min
ユーザー betrue12betrue12
提出日時 2021-04-25 15:44:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 1,516 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 204,664 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-17 14:06:01
合計ジャッジ時間 10,871 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 341 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 22 ms
4,376 KB
testcase_07 AC 293 ms
4,504 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 259 ms
4,376 KB
testcase_11 AC 121 ms
4,376 KB
testcase_12 AC 19 ms
4,380 KB
testcase_13 AC 44 ms
4,380 KB
testcase_14 AC 40 ms
4,376 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 33 ms
4,380 KB
testcase_17 AC 64 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 31 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 24 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 39 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 115 ms
4,376 KB
testcase_27 AC 20 ms
4,380 KB
testcase_28 AC 6 ms
4,380 KB
testcase_29 AC 62 ms
4,376 KB
testcase_30 AC 55 ms
4,380 KB
testcase_31 AC 15 ms
4,376 KB
testcase_32 AC 95 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 25 ms
4,380 KB
testcase_35 AC 17 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 57 ms
4,376 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 19 ms
4,380 KB
testcase_40 AC 17 ms
4,376 KB
testcase_41 AC 14 ms
4,380 KB
testcase_42 AC 13 ms
4,380 KB
testcase_43 AC 27 ms
4,380 KB
testcase_44 AC 88 ms
4,380 KB
testcase_45 AC 4 ms
4,376 KB
testcase_46 AC 19 ms
4,376 KB
testcase_47 AC 16 ms
4,380 KB
testcase_48 AC 57 ms
4,380 KB
testcase_49 AC 50 ms
4,376 KB
testcase_50 AC 4 ms
4,380 KB
testcase_51 AC 46 ms
4,376 KB
testcase_52 AC 10 ms
4,380 KB
testcase_53 AC 42 ms
4,376 KB
testcase_54 AC 92 ms
4,380 KB
testcase_55 AC 90 ms
4,376 KB
testcase_56 AC 4 ms
4,380 KB
testcase_57 AC 97 ms
4,380 KB
testcase_58 AC 68 ms
4,380 KB
testcase_59 AC 47 ms
4,376 KB
testcase_60 AC 51 ms
4,376 KB
testcase_61 AC 118 ms
4,376 KB
testcase_62 AC 114 ms
4,376 KB
testcase_63 AC 4 ms
4,376 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 124 ms
4,376 KB
testcase_66 AC 95 ms
4,376 KB
testcase_67 AC 4 ms
4,380 KB
testcase_68 AC 39 ms
4,380 KB
testcase_69 AC 80 ms
4,380 KB
testcase_70 AC 100 ms
4,376 KB
testcase_71 AC 52 ms
4,380 KB
testcase_72 AC 75 ms
4,376 KB
testcase_73 AC 99 ms
4,376 KB
testcase_74 AC 4 ms
4,376 KB
testcase_75 AC 4 ms
4,504 KB
testcase_76 AC 4 ms
4,376 KB
testcase_77 AC 4 ms
4,376 KB
testcase_78 AC 4 ms
4,380 KB
testcase_79 AC 5 ms
4,380 KB
testcase_80 AC 4 ms
4,376 KB
testcase_81 AC 4 ms
4,384 KB
testcase_82 AC 4 ms
4,376 KB
testcase_83 AC 4 ms
4,376 KB
testcase_84 AC 226 ms
4,376 KB
testcase_85 AC 225 ms
4,376 KB
testcase_86 AC 224 ms
4,376 KB
testcase_87 AC 230 ms
4,376 KB
testcase_88 AC 228 ms
4,376 KB
testcase_89 AC 231 ms
4,380 KB
testcase_90 AC 227 ms
4,380 KB
testcase_91 AC 231 ms
4,376 KB
testcase_92 AC 229 ms
4,376 KB
testcase_93 AC 220 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void chmax(int64_t& a, int64_t b){ a = max(a, b); }
void chmin(int64_t& a, int64_t b){ a = min(a, b); }

int main(){
    int K;
    int64_t N;
    cin >> K >> N;
    vector<int64_t> A(2*K), B(K);
    for(int i=0; i<K; i++) cin >> A[i];
    for(int i=0; i<K; i++) cin >> B[i];
    const int64_t INF = 1e18;

    // 最初にA[2K-1]まで求めてしまう
    for(int i=K; i<2*K; i++){
        int64_t mx = -INF;
        for(int j=0; j<K; j++) chmax(mx, min(A[i-K+j], B[j]));
        A[i] = mx;
    }
    if(N < 2*K){
        cout << A[N] << endl;
        return 0;
    }

    // A[N] >= x かどうかを返す
    auto check = [&](int64_t x)->bool{
        vector<int> S, T;
        for(int i=K; i<2*K; i++) if(A[i] >= x) S.push_back(i);
        for(int i=0; i<K; i++) if(B[i] >= x) T.push_back(K-i);
        if(T.size() == 0) return false;

        // ダイクストラ法
        int m = T[0];
        vector<int64_t> D(m, INF+1);
        for(int s : S) chmin(D[s%m], s);
        vector<bool> done(m);
        while(true){
            int s = -1;
            for(int i=0; i<m; i++) if(!done[i]) if(s == -1 || D[s] > D[i]) s = i;
            if(s == -1) break;
            for(int t : T) chmin(D[(s+t)%m], D[s] + t);
            done[s] = true;
        }

        return (D[N%m] <= N);
    };

    int64_t ok = -INF, ng = INF+1;
    while(ng-ok>1){
        int64_t mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}
0