結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー tokusakuraitokusakurai
提出日時 2021-02-10 16:35:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,405 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 218,112 KB
実行使用メモリ 54,252 KB
最終ジャッジ日時 2023-09-22 11:04:12
合計ジャッジ時間 23,570 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 25 ms
5,984 KB
testcase_19 AC 11 ms
4,452 KB
testcase_20 AC 25 ms
5,664 KB
testcase_21 AC 12 ms
4,996 KB
testcase_22 AC 15 ms
4,960 KB
testcase_23 AC 24 ms
5,756 KB
testcase_24 AC 23 ms
5,816 KB
testcase_25 AC 23 ms
5,588 KB
testcase_26 AC 26 ms
5,900 KB
testcase_27 AC 15 ms
4,984 KB
testcase_28 AC 247 ms
24,320 KB
testcase_29 AC 190 ms
19,372 KB
testcase_30 AC 165 ms
17,280 KB
testcase_31 AC 245 ms
25,836 KB
testcase_32 AC 334 ms
31,964 KB
testcase_33 AC 165 ms
17,328 KB
testcase_34 AC 303 ms
30,488 KB
testcase_35 AC 306 ms
27,380 KB
testcase_36 AC 538 ms
42,700 KB
testcase_37 AC 114 ms
15,360 KB
testcase_38 AC 234 ms
21,328 KB
testcase_39 AC 131 ms
14,864 KB
testcase_40 AC 183 ms
19,648 KB
testcase_41 AC 290 ms
25,748 KB
testcase_42 AC 434 ms
36,280 KB
testcase_43 AC 259 ms
23,816 KB
testcase_44 AC 334 ms
28,944 KB
testcase_45 AC 254 ms
24,060 KB
testcase_46 AC 321 ms
33,160 KB
testcase_47 AC 150 ms
16,676 KB
testcase_48 AC 520 ms
53,788 KB
testcase_49 AC 463 ms
53,728 KB
testcase_50 AC 536 ms
53,732 KB
testcase_51 AC 510 ms
54,028 KB
testcase_52 AC 453 ms
54,252 KB
testcase_53 AC 598 ms
53,344 KB
testcase_54 AC 569 ms
53,304 KB
testcase_55 AC 640 ms
53,720 KB
testcase_56 AC 568 ms
53,288 KB
testcase_57 AC 505 ms
54,040 KB
testcase_58 AC 74 ms
10,488 KB
testcase_59 AC 73 ms
10,384 KB
testcase_60 AC 68 ms
11,708 KB
testcase_61 AC 69 ms
11,372 KB
testcase_62 AC 69 ms
11,144 KB
testcase_63 AC 19 ms
12,360 KB
testcase_64 AC 19 ms
13,564 KB
testcase_65 AC 19 ms
14,208 KB
testcase_66 AC 19 ms
13,544 KB
testcase_67 AC 18 ms
12,656 KB
testcase_68 AC 2 ms
4,376 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 2 ms
4,376 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] << ' ' << a[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