結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー chocoruskchocorusk
提出日時 2021-01-22 22:23:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,484 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 140,376 KB
実行使用メモリ 21,256 KB
最終ジャッジ日時 2023-08-27 20:02:14
合計ジャッジ時間 36,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 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 4 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 67 ms
4,380 KB
testcase_19 AC 25 ms
4,380 KB
testcase_20 AC 72 ms
4,376 KB
testcase_21 AC 16 ms
4,380 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 49 ms
4,380 KB
testcase_24 AC 43 ms
4,380 KB
testcase_25 AC 49 ms
4,380 KB
testcase_26 AC 59 ms
4,384 KB
testcase_27 AC 39 ms
4,380 KB
testcase_28 WA -
testcase_29 AC 441 ms
7,460 KB
testcase_30 AC 405 ms
6,984 KB
testcase_31 AC 505 ms
8,984 KB
testcase_32 AC 358 ms
13,100 KB
testcase_33 AC 368 ms
6,792 KB
testcase_34 AC 525 ms
10,484 KB
testcase_35 AC 712 ms
9,500 KB
testcase_36 AC 978 ms
15,868 KB
testcase_37 AC 178 ms
6,300 KB
testcase_38 AC 553 ms
8,064 KB
testcase_39 AC 322 ms
6,304 KB
testcase_40 AC 387 ms
7,160 KB
testcase_41 AC 535 ms
9,424 KB
testcase_42 AC 1,004 ms
12,740 KB
testcase_43 AC 547 ms
8,904 KB
testcase_44 AC 737 ms
9,928 KB
testcase_45 AC 621 ms
8,300 KB
testcase_46 AC 428 ms
11,100 KB
testcase_47 AC 293 ms
6,556 KB
testcase_48 AC 1,060 ms
18,784 KB
testcase_49 AC 869 ms
17,700 KB
testcase_50 AC 1,128 ms
21,256 KB
testcase_51 AC 1,018 ms
20,432 KB
testcase_52 AC 858 ms
19,248 KB
testcase_53 AC 1,497 ms
16,468 KB
testcase_54 AC 1,439 ms
16,628 KB
testcase_55 AC 1,610 ms
16,596 KB
testcase_56 AC 1,482 ms
16,336 KB
testcase_57 AC 942 ms
16,612 KB
testcase_58 AC 661 ms
16,580 KB
testcase_59 AC 662 ms
16,420 KB
testcase_60 AC 662 ms
16,620 KB
testcase_61 AC 668 ms
16,416 KB
testcase_62 AC 661 ms
17,984 KB
testcase_63 AC 18 ms
12,632 KB
testcase_64 AC 18 ms
15,060 KB
testcase_65 AC 17 ms
12,720 KB
testcase_66 AC 18 ms
12,444 KB
testcase_67 AC 18 ms
12,144 KB
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 2 ms
4,380 KB
testcase_73 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int k, l, m, n; cin>>k>>l>>m>>n;
    ll s; cin>>s;
    ll a[606], b[606], c[606], d[606];
    for(int i=0; i<k; i++) cin>>a[i];
    for(int i=0; i<l; i++) cin>>b[i];
    for(int i=0; i<m; i++) cin>>c[i];
    for(int i=0; i<n; i++) cin>>d[i];
    vector<ll> ab, cd;
    for(int i=0; i<k; i++) for(int j=0; j<l; j++) ab.push_back(a[i]*b[j]);
    for(int i=0; i<m; i++) for(int j=0; j<n; j++) cd.push_back(c[i]*d[j]);
    sort(ab.begin(), ab.end());
    sort(cd.begin(), cd.end());
    ll i1=lower_bound(ab.begin(), ab.end(), 0)-ab.begin();
    ll i2=upper_bound(ab.begin(), ab.end(), 0)-ab.begin();
    ll j1=lower_bound(cd.begin(), cd.end(), 0)-cd.begin();
    ll j2=upper_bound(cd.begin(), cd.end(), 0)-cd.begin();
    ll kl=ab.size(), mn=cd.size();
    ll c1=i1*(mn-j2)+j1*(kl-i2);
    if(s<=c1){
        vector<ll> v1, v2, w1, w2;
        for(int i=0; i<kl; i++){
            if(ab[i]<0) v1.push_back(-ab[i]);
            else if(ab[i]>0) v2.push_back(ab[i]);
        }
        for(int i=0; i<mn; i++){
            if(cd[i]<0) w1.push_back(-cd[i]);
            else if(cd[i]>0) w2.push_back(cd[i]);
        }
        reverse(v1.begin(), v1.end());
        reverse(w1.begin(), w1.end());
        s=c1+1-s;
        ll le=0, r=1e18;
        while(r-le>1){
            ll mid=(le+r)/2;
            ll cnt=0;
            for(auto z:v1){
                cnt+=upper_bound(w2.begin(), w2.end(), mid/z)-w2.begin();
            }
            for(auto z:v2){
                cnt+=upper_bound(w1.begin(), w1.end(), mid/z)-w1.begin();
            }
            if(cnt>=s) r=mid;
            else le=mid;
        }
        cout<<-r<<endl;
        int p1=0, p2=0;
        for(int i=0; i<kl; i++){
            if(ab[i]!=0 && r%ab[i]==0){
                int t=lower_bound(cd.begin(), cd.end(), -r/ab[i])-cd.begin();
                if(t<mn && cd[t]==-r/ab[i]){
                    p1=i, p2=t;
                    break;
                }
            }
        }
        bool ok=0;
        for(int i=0; i<k; i++){
            for(int j=0; j<l; j++){
                if(a[i]*b[j]==ab[p1]){
                    cout<<a[i]<<" "<<b[j]<<" ";
                    ok=1;
                    break;
                }
            }
            if(ok)break;
        }
        for(int i=0; i<m; i++){
            for(int j=0; j<n; j++){
                if(c[i]*d[j]==cd[p2]){
                    cout<<c[i]<<" "<<d[j]<<endl;
                    return 0;
                }
            }
        }
    }else if(s<=c1+(i2-i1)*(j2-j1)){
        cout<<0<<endl;
        for(int i=0; i<k; i++){
            if(a[i]==0){
                cout<<0<<" "<<b[0]<<" "<<c[0]<<" "<<d[0]<<endl;
                return 0;
            }
        }
        for(int i=0; i<l; i++){
            if(b[i]==0){
                cout<<a[0]<<" "<<0<<" "<<c[0]<<" "<<d[0]<<endl;
                return 0;
            }
        }
        for(int i=0; i<m; i++){
            if(c[i]==0){
                cout<<a[0]<<" "<<b[0]<<" "<<0<<" "<<d[0]<<endl;
                return 0;
            }
        }
        for(int i=0; i<n; i++){
            if(d[i]==0){
                cout<<a[0]<<" "<<b[0]<<" "<<c[0]<<" "<<0<<endl;
                return 0;
            }
        }
    }else{
        s-=c1+(i2-i1)*(j2-j1);
        vector<ll> v1, v2, w1, w2;
        for(int i=0; i<kl; i++){
            if(ab[i]<0) v1.push_back(-ab[i]);
            else if(ab[i]>0) v2.push_back(ab[i]);
        }
        for(int i=0; i<mn; i++){
            if(cd[i]<0) w1.push_back(-cd[i]);
            else if(cd[i]>0) w2.push_back(cd[i]);
        }
        reverse(v1.begin(), v1.end());
        reverse(w1.begin(), w1.end());
        ll le=0, r=1e18;
        while(r-le>1){
            ll mid=(le+r)/2;
            ll cnt=0;
            for(auto z:v1){
                cnt+=upper_bound(w1.begin(), w1.end(), mid/z)-w1.begin();
            }
            for(auto z:v2){
                cnt+=upper_bound(w2.begin(), w2.end(), mid/z)-w2.begin();
            }
            if(cnt>=s) r=mid;
            else le=mid;
        }
        cout<<r<<endl;
        int p1=0, p2=0;
        for(int i=0; i<kl; i++){
            if(ab[i]!=0 && r%ab[i]==0){
                int t=lower_bound(cd.begin(), cd.end(), r/ab[i])-cd.begin();
                if(t<mn && cd[t]*ab[i]==r){
                    p1=i, p2=t;
                    break;
                }
            }
        }
        bool ok=0;
        for(int i=0; i<k; i++){
            for(int j=0; j<l; j++){
                if(a[i]*b[j]==ab[p1]){
                    cout<<a[i]<<" "<<b[j]<<" ";
                    ok=1;
                    break;
                }
            }
            if(ok)break;
        }
        for(int i=0; i<m; i++){
            for(int j=0; j<n; j++){
                if(c[i]*d[j]==cd[p2]){
                    cout<<c[i]<<" "<<d[j]<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}
0