結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー vkgainzvkgainz
提出日時 2021-06-12 11:06:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,373 bytes
コンパイル時間 10,728 ms
コンパイル使用メモリ 136,564 KB
実行使用メモリ 140,944 KB
最終ジャッジ日時 2023-08-22 08:25:32
合計ジャッジ時間 19,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 15 ms
4,376 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 16 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 10 ms
4,380 KB
testcase_28 RE -
testcase_29 AC 112 ms
5,320 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 143 ms
6,816 KB
testcase_35 AC 165 ms
6,816 KB
testcase_36 AC 254 ms
9,340 KB
testcase_37 AC 59 ms
4,884 KB
testcase_38 AC 121 ms
5,760 KB
testcase_39 WA -
testcase_40 AC 97 ms
5,332 KB
testcase_41 AC 147 ms
6,512 KB
testcase_42 WA -
testcase_43 AC 142 ms
5,916 KB
testcase_44 WA -
testcase_45 AC 133 ms
5,960 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 233 ms
10,348 KB
testcase_49 AC 185 ms
10,296 KB
testcase_50 AC 248 ms
10,260 KB
testcase_51 AC 221 ms
10,300 KB
testcase_52 AC 192 ms
10,356 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 344 ms
11,056 KB
testcase_56 WA -
testcase_57 AC 208 ms
11,048 KB
testcase_58 AC 123 ms
11,004 KB
testcase_59 AC 123 ms
11,064 KB
testcase_60 AC 123 ms
11,048 KB
testcase_61 AC 123 ms
11,048 KB
testcase_62 AC 124 ms
11,052 KB
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 AC 2 ms
4,380 KB
testcase_71 AC 1 ms
4,376 KB
testcase_72 AC 2 ms
4,376 KB
testcase_73 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void read(vector<int> &v, int sz) {
    for(int i = 0; i < sz; i++) {
        cin >> v[i];
    }
}

long long get_floor(long long lo, long long hi) {
    long long x = (lo + hi);
    if(abs(x) % 2 == 0) return x / 2;
    if(x > 0) return x / 2;
    return (x - 1) / 2;
}

long long solve(vector<int> &x, vector<int> &y, long long mid) {
    int j = (int) y.size() - 1;
    long long ans = 0LL;
    for(int i = 0; i < (int) x.size(); i++) {
        while(j >= 0 && x[i] * 1LL * y[j] > mid)
            --j;
        ans += j + 1;
    }
    return ans;
}

long long solve2(vector<int> &x, vector<int> &y, long long mid) {
    int j = (int) y.size() - 1;
    long long ans = 0LL;
    for(int i = (int) x.size() - 1; i >= 0; i--) {
        while(j >= 0 && x[i] * 1LL * y[j] <= mid)
            --j;
        ans += (int) y.size() - 1 - j;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int K, L, M, N;
    long long S;
    cin >> K >> L >> M >> N >> S;
    vector<int> A(K), B(L), C(M), D(N);
    read(A, K);
    read(B, L);
    read(C, M);
    read(D, N);
    vector<int> fl, fr;
    for(int i = 0; i < K; i++)
        for(int j = 0; j < L; j++)
            fl.push_back(A[i] * B[j]);
    sort(fl.begin(), fl.end());
    for(int i = 0; i < M; i++)
        for(int j = 0; j < N; j++)
            fr.push_back(C[i] * D[j]);
    sort(fr.begin(), fr.end());
    vector<vector<int>> l(2), r(2);
    int zl = 0, zr = 0;
    for(int i = 0; i < K; i++) {
        for(int j = 0; j < L; j++) {
            if(A[i] * B[j] > 0) l[0].push_back(A[i] * B[j]);
            else if(A[i] * B[j] == 0) ++zl;
            else l[1].push_back(A[i] * B[j]);
        }
    }
    for(int i = 0; i < M; i++) {
        for(int j = 0; j < N; j++) {
            if(C[i] * D[j] > 0) r[0].push_back(C[i] * D[j]);
            else if(C[i] * D[j] == 0) ++zr;
            else r[1].push_back(C[i] * D[j]);
        }
    }
    for(int i = 0; i < 2; i++)
        sort(l[i].begin(), l[i].end()), sort(r[i].begin(), r[i].end());
    reverse(l[1].begin(), l[1].end());
    reverse(r[1].begin(), r[1].end());
    long long lo = -1e18, hi = 1e18;
    for(int j = 0; j < 62; j++) {
        long long mid = get_floor(lo, hi);
        long long num = 0LL;
        num += solve(l[0], r[0], mid);
        num += solve(l[1], r[1], mid);
        num += solve2(l[0], r[1], mid);
        num += solve2(r[0], l[1], mid);
        if(mid >= 0) num += zl * 1LL * zr + zl * 1LL * M * N + zr * 1LL * K * L;
        if(num < S) lo = mid + 1;
        else hi = mid;

    }
    long long T = lo;
    long long left = 0LL, right = 0LL;
    for(int i = 0; i < K * L; i++)
        if(T % fl[i] == 0) {
            int it = lower_bound(fr.begin(), fr.end(), T / fl[i]) - fr.begin();
            if(fr[it] == T / fl[i])
                left = fl[i], right = T / fl[i];
        }
    pair<int, int> x, y;
    for(int i = 0; i < K; i++) {
        for(int j = 0; j < L; j++) {
            if(A[i] * 1LL * B[j] == left)
                x = {A[i], B[j]};
        }
    }
    for(int i = 0; i < M; i++) {
        for(int j = 0; j < N; j++) {
            if(C[i] * 1LL * D[j] == right)
                y = {C[i], D[j]};
        }
    }
    cout << T << "\n";
    cout << x.first << " " << x.second << " " << y.first << " " << y.second << "\n";
}
0