結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー firiexpfiriexp
提出日時 2021-01-22 23:34:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,145 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 112,640 KB
実行使用メモリ 12,508 KB
最終ジャッジ日時 2024-06-08 18:40:30
合計ジャッジ時間 13,553 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 5 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 9 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 82 ms
5,624 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 99 ms
7,012 KB
testcase_35 AC 130 ms
7,516 KB
testcase_36 AC 179 ms
8,664 KB
testcase_37 AC 40 ms
5,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 68 ms
5,516 KB
testcase_41 AC 109 ms
5,964 KB
testcase_42 WA -
testcase_43 AC 108 ms
7,008 KB
testcase_44 WA -
testcase_45 AC 112 ms
6,104 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 140 ms
11,472 KB
testcase_58 AC 73 ms
11,492 KB
testcase_59 AC 70 ms
11,488 KB
testcase_60 AC 61 ms
11,488 KB
testcase_61 AC 60 ms
11,488 KB
testcase_62 AC 59 ms
11,620 KB
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 AC 2 ms
5,376 KB
testcase_73 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int a, b, c, d;
    ll s;
    cin >> a >> b >> c >> d >> s;
    vector<int> A(a), B(b), C(c), D(d);
    for (auto &&i : A) scanf("%d", &i);
    for (auto &&i : B) scanf("%d", &i);
    for (auto &&i : C) scanf("%d", &i);
    for (auto &&i : D) scanf("%d", &i);
    vector<ll> vp, up, vm, um;
    for (int i = 0; i < a; ++i) {
        for (int j = 0; j < b; ++j) {
            if(A[i]*B[j] >= 0) vp.emplace_back(A[i] * B[j]);
            else vm.emplace_back(A[i] * B[j]);
        }
    }
    for (int i = 0; i < c; ++i) {
        for (int j = 0; j < d; ++j) {
            if(C[i]*D[j] >= 0) up.emplace_back(C[i] * D[j]);
            else um.emplace_back(C[i] * D[j]);
        }
    }
    sort(vp.begin(),vp.end());
    sort(vm.begin(),vm.end());
    sort(up.begin(),up.end());
    sort(um.begin(),um.end());
    ll ok = INF<ll>, ng = -INF<ll>;
    while(ok-ng > 1){
        ll mid = (ok+ng)/2;
        if([&](ll x) -> bool{ // count v[i]*u[j] <= x
            ll cnt = 0;
            if(x >= 0){
                cnt += (ll)vp.size()*um.size()+(ll)up.size()*vm.size();
                int cur = 0;
                for (int i = (int)vp.size()-1; i >= 0; --i) { // v >= 0, u >= 0
                    while(cur < up.size() && up[cur]*vp[i] <= x) cur++;
                    cnt += cur;
                }
                cur = um.size();
                for (int i = 0; i < vm.size(); ++i) {
                    while(cur > 0 && vm[i]*um[cur-1] <= x) cur--;
                    cnt += um.size()-cur;
                }
            }else {
                int cur = 0;
                for (int i = (int)vp.size()-1; i >= 0; --i) {
                    while(cur < um.size() && um[cur]*vp[i] <= x) cur++;
                    cnt += cur;
                }
                cur = 0;
                for (int i = (int)vm.size(); i >= 0; --i) {
                    while(cur < up.size() && up[cur]*vm[i] <= x) cur++;
                    cnt += cur;
                }
            }
            return cnt >= s;
        }(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";

    // 復元いる?
    ll ab = 0, cd = 0;
    [&](ll x) -> void { // count v[i]*u[j] <= x
        ll cnt = 0;
        if(x >= 0){
            cnt += (ll)vp.size()*um.size()+(ll)up.size()*vm.size();
            int cur = 0;
            for (int i = (int)vp.size()-1; i >= 0; --i) { // v >= 0, u >= 0
                while(cur < up.size() && up[cur]*vp[i] < x) cur++;
                if(cur < up.size() && up[cur]*vp[i] == x) ab = up[cur], cd = vp[i];
            }
            cur = um.size();
            for (int i = 0; i < vm.size(); ++i) {
                while(cur > 0 && vm[i]*um[cur-1] < x) cur--;
                if(cur > 0 && vm[i]*um[cur-1] == x) ab = vm[i], cd = um[cur-1];
            }
        }else {
            int cur = 0;
            for (int i = (int)vp.size()-1; i >= 0; --i) {
                while(cur < um.size() && um[cur]*vp[i] < x) cur++;
                if(cur < um.size() && um[cur]*vp[i] == x) ab = vp[i], cd = um[cur];
            }
            cur = 0;
            for (int i = (int)vm.size(); i >= 0; --i) {
                while(cur < up.size() && up[cur]*vm[i] < x) cur++;
                if(cur < up.size() && up[cur]*vm[i] == x) ab = vp[cur], cd = vm[i];
            }
        }
    }(ok);

    for (int i = 0; i < a; ++i) {
        for (int j = 0; j < b; ++j) {
            if(A[i]*B[j] == ab){
                cout << A[i] << " " << B[j] << " ";
                i = a; j = b;
            }
        }
    }
    for (int i = 0; i < c; ++i) {
        for (int j = 0; j < d; ++j) {
            if(C[i]*D[j] == cd){
                cout << C[i] << " " << D[j] << "\n";
                i = c; j = d;
            }
        }
    }
    return 0;
}
0