結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー vkgainzvkgainz
提出日時 2021-06-12 10:06:52
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,542 bytes
コンパイル時間 3,397 ms
コンパイル使用メモリ 166,400 KB
実行使用メモリ 70,656 KB
最終ジャッジ日時 2024-12-16 02:22:37
合計ジャッジ時間 91,666 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42 RE * 8 TLE * 24
権限があれば一括ダウンロードができます

ソースコード

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;
}

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);
    map<long long, int> fl, fr;
    for(int i = 0; i < K; i++)
        for(int j = 0; j < L; j++)
            ++fl[A[i] * B[j]];
    for(int i = 0; i < M; i++)
        for(int j = 0; j < N; j++)
            ++fr[C[i] * D[j]];
    int sum = 0;
    for(auto [a, b] : fr) {
        sum += b;
        fr[a] = sum;
    }
    long long T;
    long long lo = -1e18, hi = 1e18;
    for(int j = 0; j < 62; j++) {
        long long mid = get_floor(lo, hi);
        long long num = 0LL;
        for(auto [a, b] : fl) {
            if(a > 0) {
                long long look = mid / a;
                if(mid < 0) look = (mid - a + 1) / a;
                auto it = fr.upper_bound(look);
                if(it == fr.begin()) continue;
                --it;
                num += b * 1LL * it->second;
            }
            else if(a < 0) {
                long long look;
                if(mid > 0) look = - (mid / (- a));
                else look = (-mid - a - 1) / (-a);
                auto it = fr.lower_bound(look);
                num += b * 1LL * sum;
                if(it == fr.begin()) continue;
                --it;
                num -= b * 1LL * it->second;
            }
            else {
                if(mid >= 0) num += b * 1LL * sum;
            }
        }
        if(num < S) lo = mid + 1;
        else hi = mid;
    }
    T = lo;
    long long left = 0LL, right = 0LL;
    pair<int, int> x, y;
    for(auto [a, b] : fl) {
        if(T % a == 0 && fr.find(T / a) != fr.end())
            left = a, right = T / a;
    }
    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