結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー chocoruskchocorusk
提出日時 2021-01-22 22:20:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,800 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 138,400 KB
実行使用メモリ 20,424 KB
最終ジャッジ日時 2023-08-27 19:56:53
合計ジャッジ時間 31,780 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 67 ms
4,376 KB
testcase_19 AC 25 ms
4,376 KB
testcase_20 AC 72 ms
4,376 KB
testcase_21 AC 16 ms
4,376 KB
testcase_22 AC 33 ms
4,376 KB
testcase_23 AC 49 ms
4,376 KB
testcase_24 AC 43 ms
4,380 KB
testcase_25 AC 49 ms
4,376 KB
testcase_26 AC 60 ms
4,380 KB
testcase_27 AC 39 ms
4,380 KB
testcase_28 WA -
testcase_29 AC 436 ms
7,288 KB
testcase_30 AC 407 ms
6,752 KB
testcase_31 AC 505 ms
8,916 KB
testcase_32 AC 365 ms
12,436 KB
testcase_33 AC 370 ms
6,840 KB
testcase_34 AC 519 ms
10,428 KB
testcase_35 AC 715 ms
9,384 KB
testcase_36 AC 983 ms
14,412 KB
testcase_37 AC 176 ms
6,368 KB
testcase_38 AC 553 ms
7,784 KB
testcase_39 AC 321 ms
6,196 KB
testcase_40 AC 385 ms
7,092 KB
testcase_41 AC 543 ms
9,352 KB
testcase_42 AC 1,010 ms
13,544 KB
testcase_43 AC 542 ms
8,788 KB
testcase_44 AC 738 ms
9,848 KB
testcase_45 AC 621 ms
8,404 KB
testcase_46 AC 432 ms
11,032 KB
testcase_47 AC 296 ms
6,440 KB
testcase_48 AC 1,044 ms
17,784 KB
testcase_49 AC 885 ms
18,020 KB
testcase_50 AC 1,116 ms
18,068 KB
testcase_51 AC 1,028 ms
18,256 KB
testcase_52 AC 824 ms
18,388 KB
testcase_53 AC 1,519 ms
17,304 KB
testcase_54 AC 1,457 ms
18,272 KB
testcase_55 AC 1,618 ms
16,212 KB
testcase_56 AC 1,493 ms
18,320 KB
testcase_57 AC 946 ms
16,776 KB
testcase_58 AC 665 ms
16,716 KB
testcase_59 AC 671 ms
16,516 KB
testcase_60 AC 656 ms
20,424 KB
testcase_61 AC 676 ms
18,376 KB
testcase_62 AC 677 ms
18,500 KB
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 2 ms
4,384 KB
testcase_73 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    }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