結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー chocoruskchocorusk
提出日時 2021-01-22 22:25:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,597 ms / 2,000 ms
コード長 5,502 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 139,480 KB
実行使用メモリ 22,792 KB
最終ジャッジ日時 2023-08-27 20:09:37
合計ジャッジ時間 36,628 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 67 ms
4,380 KB
testcase_19 AC 25 ms
4,380 KB
testcase_20 AC 72 ms
4,380 KB
testcase_21 AC 16 ms
4,380 KB
testcase_22 AC 33 ms
4,376 KB
testcase_23 AC 49 ms
4,376 KB
testcase_24 AC 42 ms
4,380 KB
testcase_25 AC 48 ms
4,380 KB
testcase_26 AC 59 ms
4,380 KB
testcase_27 AC 38 ms
4,380 KB
testcase_28 AC 475 ms
8,724 KB
testcase_29 AC 430 ms
7,500 KB
testcase_30 AC 403 ms
6,812 KB
testcase_31 AC 504 ms
9,016 KB
testcase_32 AC 362 ms
12,168 KB
testcase_33 AC 367 ms
6,804 KB
testcase_34 AC 515 ms
10,256 KB
testcase_35 AC 698 ms
9,268 KB
testcase_36 AC 965 ms
14,672 KB
testcase_37 AC 176 ms
6,248 KB
testcase_38 AC 550 ms
7,724 KB
testcase_39 AC 319 ms
6,068 KB
testcase_40 AC 384 ms
7,092 KB
testcase_41 AC 532 ms
9,400 KB
testcase_42 AC 1,005 ms
13,604 KB
testcase_43 AC 537 ms
9,096 KB
testcase_44 AC 736 ms
9,740 KB
testcase_45 AC 615 ms
8,372 KB
testcase_46 AC 428 ms
10,896 KB
testcase_47 AC 292 ms
6,392 KB
testcase_48 AC 1,044 ms
17,828 KB
testcase_49 AC 884 ms
22,792 KB
testcase_50 AC 1,115 ms
18,180 KB
testcase_51 AC 1,028 ms
19,112 KB
testcase_52 AC 820 ms
18,536 KB
testcase_53 AC 1,500 ms
16,972 KB
testcase_54 AC 1,438 ms
16,216 KB
testcase_55 AC 1,597 ms
17,412 KB
testcase_56 AC 1,473 ms
16,448 KB
testcase_57 AC 943 ms
18,004 KB
testcase_58 AC 657 ms
18,968 KB
testcase_59 AC 665 ms
17,676 KB
testcase_60 AC 655 ms
18,080 KB
testcase_61 AC 653 ms
16,728 KB
testcase_62 AC 665 ms
16,508 KB
testcase_63 AC 18 ms
12,732 KB
testcase_64 AC 20 ms
12,348 KB
testcase_65 AC 19 ms
12,220 KB
testcase_66 AC 19 ms
14,104 KB
testcase_67 AC 18 ms
12,064 KB
testcase_68 AC 2 ms
4,380 KB
testcase_69 AC 2 ms
4,384 KB
testcase_70 AC 1 ms
4,380 KB
testcase_71 AC 2 ms
4,380 KB
testcase_72 AC 2 ms
4,380 KB
testcase_73 AC 1 ms
4,380 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<=kl*mn-i1*j1-(kl-i2)*(mn-j2)){
        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-=kl*mn-i1*j1-(kl-i2)*(mn-j2);
        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