結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2020-11-01 17:28:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,949 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 95,072 KB
実行使用メモリ 10,348 KB
最終ジャッジ日時 2023-08-27 16:15:53
合計ジャッジ時間 17,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 25 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 24 ms
4,376 KB
testcase_21 AC 19 ms
4,376 KB
testcase_22 AC 21 ms
4,380 KB
testcase_23 AC 30 ms
4,380 KB
testcase_24 AC 35 ms
4,380 KB
testcase_25 AC 31 ms
4,376 KB
testcase_26 AC 32 ms
4,380 KB
testcase_27 AC 18 ms
4,380 KB
testcase_28 AC 249 ms
10,348 KB
testcase_29 RE -
testcase_30 AC 160 ms
6,892 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 158 ms
6,976 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 144 ms
6,712 KB
testcase_38 AC 188 ms
8,032 KB
testcase_39 AC 123 ms
6,568 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 AC 2 ms
4,380 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 2 ms
4,380 KB
testcase_71 AC 2 ms
4,380 KB
testcase_72 AC 1 ms
4,380 KB
testcase_73 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cassert>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<lint,int>pli;
#define rep(i,n)for(int i=0;i<(int)(n);++i)
int k,l,m,n;
lint s;
const int N=501;
const int NLIMIT=500;
const lint VLIMIT=30000;
lint a[N],b[N],c[N],d[N];
void in_range(lint a,lint b,lint c){
  assert(b<=a&&a<=c);
}
lint quo(lint a,lint b){
  assert(b>0);
  lint q=a/b;
  if(a<q*b)q--;
  return q;
}
int main(){
  cin>>k>>l>>m>>n>>s;
  rep(i,k)cin>>a[i];
  rep(i,l)cin>>b[i];
  rep(i,m)cin>>c[i];
  rep(i,n)cin>>d[i];
  //入力が妥当か確認する。
  in_range(k,1,NLIMIT);
  in_range(l,1,NLIMIT);
  in_range(m,1,NLIMIT);
  in_range(n,1,NLIMIT);
  in_range(s,1,lint(k)*l*m*n);
  rep(i,k)in_range(a[i],-VLIMIT,VLIMIT);
  rep(i,l)in_range(b[l],-VLIMIT,VLIMIT);
  rep(i,m)in_range(c[m],-VLIMIT,VLIMIT);
  rep(i,n)in_range(d[n],-VLIMIT,VLIMIT);
  //平方分割
  vector<pli>frm;
  vector<lint>lat,latneg,latpos;
  lint lat0=0;
  rep(i,k)rep(j,l)frm.push_back(pli(a[i]*b[j],i*l+j));
  rep(i,m)rep(j,n)lat.push_back(c[i]*d[j]);
  sort(frm.begin(),frm.end());
  for(lint x:lat){
    if(x>0)latpos.push_back(x);
    if(x<0)latneg.push_back(-x);
    if(x==0)lat0++;
  }
  sort(latpos.begin(),latpos.end());
  sort(latneg.rbegin(),latneg.rend());
  //二分探索。x 以下の要素が s 個以上になる最小の x が欲しい。
  //8.1*10^17 を包む値
  lint pass=1e18,fail=-1e18;
  while(pass-fail>1){
    lint mid=fail+(pass-fail)/2;
    lint count=mid>=0?lat0*k*l:0;
    int pos=k*l;
    //尺取り
    if(mid>=0){
      rep(i,latpos.size()){
        lint div=latpos[i];
        lint q=quo(mid,div);
        while(pos>0&&frm[pos-1].first>q)pos--;
        count+=pos;
      }
      pos=0;
      for(int i=(int)latneg.size()-1;i>=0;i--){
        lint div=latneg[i];
        lint q=quo(-mid+div-1,div);
        while(pos<k*l&&frm[pos].first<q)pos++;
        count+=k*l-pos;
      }
    }else{
      for(int i=(int)latpos.size()-1;i>=0;i--){
        lint div=latpos[i];
        lint q=quo(mid,div);
        while(pos>0&&frm[pos-1].first>q)pos--;
        count+=pos;
      }
      pos=0;
      rep(i,latneg.size()){
        lint div=latneg[i];
        lint q=quo(-mid+div-1,div);
        while(pos<k*l&&frm[pos].first<q)pos++;
        count+=k*l-pos;
      }
    }
    if(count>=s)pass=mid;
    else fail=mid;
  }
  cout<<pass<<endl;
  rep(i,m*n){
    // 解が見つかる?
    int i0=i/n,i1=i%n;
    lint div=lat[i];
    if(div==0){
      if(pass==0){
        cout<<a[0]<<" "<<b[0]<<" "<<c[i0]<<" "<<d[i1]<<endl;
        return 0;
      }else continue;
    }
    if(pass%div!=0)continue;
    lint q=pass/div;
    int idx=lower_bound(frm.begin(),frm.end(),pli(q,-1))-frm.begin();
    if(frm[idx].first==q){
      int j0=frm[idx].second/l;
      int j1=frm[idx].second%l;
      cout<<a[j0]<<" "<<b[j1]<<" "<<c[i0]<<" "<<d[i1]<<endl;
      return 0;
    }
  }
  assert(0);
}
0