結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー tokusakuraitokusakurai
提出日時 2021-02-10 16:37:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 657 ms / 2,000 ms
コード長 3,405 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 219,532 KB
実行使用メモリ 54,356 KB
最終ジャッジ日時 2023-09-22 11:06:18
合計ジャッジ時間 22,622 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 25 ms
5,968 KB
testcase_19 AC 11 ms
4,412 KB
testcase_20 AC 26 ms
5,760 KB
testcase_21 AC 11 ms
4,944 KB
testcase_22 AC 16 ms
4,860 KB
testcase_23 AC 24 ms
5,748 KB
testcase_24 AC 24 ms
5,864 KB
testcase_25 AC 24 ms
5,584 KB
testcase_26 AC 28 ms
5,840 KB
testcase_27 AC 15 ms
4,888 KB
testcase_28 AC 256 ms
24,408 KB
testcase_29 AC 198 ms
19,540 KB
testcase_30 AC 171 ms
17,228 KB
testcase_31 AC 245 ms
25,952 KB
testcase_32 AC 335 ms
32,548 KB
testcase_33 AC 166 ms
17,376 KB
testcase_34 AC 310 ms
30,488 KB
testcase_35 AC 309 ms
27,656 KB
testcase_36 AC 536 ms
42,504 KB
testcase_37 AC 119 ms
15,560 KB
testcase_38 AC 238 ms
21,392 KB
testcase_39 AC 128 ms
14,872 KB
testcase_40 AC 187 ms
19,820 KB
testcase_41 AC 296 ms
25,704 KB
testcase_42 AC 457 ms
36,328 KB
testcase_43 AC 267 ms
23,748 KB
testcase_44 AC 348 ms
28,948 KB
testcase_45 AC 256 ms
23,952 KB
testcase_46 AC 332 ms
33,044 KB
testcase_47 AC 149 ms
16,860 KB
testcase_48 AC 515 ms
54,356 KB
testcase_49 AC 466 ms
53,948 KB
testcase_50 AC 531 ms
53,676 KB
testcase_51 AC 510 ms
53,528 KB
testcase_52 AC 450 ms
53,900 KB
testcase_53 AC 602 ms
53,796 KB
testcase_54 AC 601 ms
53,420 KB
testcase_55 AC 657 ms
53,600 KB
testcase_56 AC 566 ms
53,460 KB
testcase_57 AC 503 ms
54,032 KB
testcase_58 AC 77 ms
11,344 KB
testcase_59 AC 77 ms
11,108 KB
testcase_60 AC 71 ms
10,492 KB
testcase_61 AC 70 ms
10,584 KB
testcase_62 AC 70 ms
11,812 KB
testcase_63 AC 20 ms
12,124 KB
testcase_64 AC 19 ms
12,520 KB
testcase_65 AC 19 ms
12,216 KB
testcase_66 AC 20 ms
12,296 KB
testcase_67 AC 20 ms
12,500 KB
testcase_68 AC 1 ms
4,380 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 2 ms
4,380 KB
testcase_71 AC 1 ms
4,380 KB
testcase_72 AC 1 ms
4,380 KB
testcase_73 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main(){
    int A, B, C, D; ll K; cin >> A >> B >> C >> D >> K;

    vector<ll> a(A), b(B), c(C), d(D);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, C) cin >> c[i];
    rep(i, D) cin >> d[i];

    vector<ll> P1, P2, P3, Q;
    map<ll, pii> mp1, mp2;
    rep(i, A){
        rep(j, B){
            ll x = a[i]*b[j];
            if(x > 0) P1.eb(x);
            if(x == 0) P2.eb(x);
            if(x < 0) P3.eb(-x);
            mp1[a[i]*b[j]] = pii(i, j);
        }
    }

    sort(all(P1)), sort(all(P3));

    rep(i, C){
        rep(j, D){
            Q.eb(c[i]*d[j]);
            mp2[c[i]*d[j]] = pii(i, j);
        }
    }

    sort(all(Q));
    int N = sz(Q);

    ll L = -INF, R = INF; //(L,R]
    while(R-L > 1){
        ll M = (L+R)/2;
        ll cnt = 0;
        
        int ptr;

        if(M >= 0){
            ptr = N;
            each(e, P1){
                while(ptr > 0 && e*Q[ptr-1] > M) ptr--;
                cnt += ptr;
            }

            cnt += 1LL*sz(P2)*N;

            ptr = 0;
            each(e, P3){
                while(ptr < N && e*Q[ptr] < -M) ptr++;
                cnt += N-ptr;
            }
        }

        else{
            ptr = 0;
            each(e, P1){
                while(ptr < N && e*Q[ptr] <= M) ptr++;
                cnt += ptr;
            }

            ptr = N;
            each(e, P3){
                while(ptr > 0 && e*Q[ptr-1] >= -M) ptr--;
                cnt += N-ptr;
            }
        }

        (cnt >= K? R : L) = M;
    }

    cout << R << '\n';

    if(R == 0){
        each(e, mp1){
            if(e.first != 0) continue;
            auto [i, j] = e.second;
            cout << a[i] << ' ' << b[j] << ' ' << c[0] << ' ' << d[0] << '\n';
            return 0;
        }
        each(e, mp2){
            if(e.first != 0) continue;
            auto [i, j] = e.second;
            cout << a[0] << ' ' << b[0] << ' ' << c[i] << ' ' << d[j] << '\n';
            return 0;
        }
    }

    each(e, mp1){
        if(e.first == 0) continue;
        int flag = 0;
        if(R < 0) flag ^= 1;
        if(e.first < 0) flag ^= 1;

        if(abs(R)%abs(e.first) != 0) continue;
        ll x = abs(R)/abs(e.first);
        if(flag) x *= -1;

        if(mp2.count(x)){
            auto [i, j] = e.second;
            auto [k, l] = mp2[x];
            cout << a[i] << ' ' << b[j] << ' ' << c[k] << ' ' << d[l] << '\n';
            return 0;
        }
    }
}
0