結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2020-11-01 18:03:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 641 ms / 2,000 ms
コード長 2,949 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 93,792 KB
実行使用メモリ 22,376 KB
最終ジャッジ日時 2023-08-27 16:17:25
合計ジャッジ時間 23,203 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 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,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 24 ms
4,376 KB
testcase_19 AC 12 ms
4,380 KB
testcase_20 AC 25 ms
4,376 KB
testcase_21 AC 19 ms
4,376 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 31 ms
4,380 KB
testcase_24 AC 36 ms
4,376 KB
testcase_25 AC 31 ms
4,376 KB
testcase_26 AC 33 ms
4,384 KB
testcase_27 AC 18 ms
4,376 KB
testcase_28 AC 252 ms
9,660 KB
testcase_29 AC 198 ms
7,240 KB
testcase_30 AC 161 ms
6,904 KB
testcase_31 AC 209 ms
9,704 KB
testcase_32 AC 354 ms
12,564 KB
testcase_33 AC 158 ms
6,916 KB
testcase_34 AC 297 ms
11,112 KB
testcase_35 AC 268 ms
10,324 KB
testcase_36 AC 475 ms
14,336 KB
testcase_37 AC 144 ms
6,552 KB
testcase_38 AC 191 ms
7,948 KB
testcase_39 AC 125 ms
6,396 KB
testcase_40 AC 176 ms
7,184 KB
testcase_41 AC 298 ms
8,956 KB
testcase_42 AC 382 ms
12,128 KB
testcase_43 AC 266 ms
10,260 KB
testcase_44 AC 281 ms
10,896 KB
testcase_45 AC 211 ms
8,332 KB
testcase_46 AC 285 ms
11,844 KB
testcase_47 AC 175 ms
7,180 KB
testcase_48 AC 475 ms
19,976 KB
testcase_49 AC 374 ms
20,092 KB
testcase_50 AC 497 ms
18,540 KB
testcase_51 AC 432 ms
19,432 KB
testcase_52 AC 413 ms
22,376 KB
testcase_53 AC 638 ms
17,824 KB
testcase_54 AC 621 ms
18,264 KB
testcase_55 AC 641 ms
17,468 KB
testcase_56 AC 631 ms
18,124 KB
testcase_57 AC 449 ms
18,844 KB
testcase_58 AC 352 ms
18,696 KB
testcase_59 AC 355 ms
18,512 KB
testcase_60 AC 371 ms
17,940 KB
testcase_61 AC 369 ms
17,504 KB
testcase_62 AC 368 ms
17,880 KB
testcase_63 AC 34 ms
17,180 KB
testcase_64 AC 33 ms
16,424 KB
testcase_65 AC 34 ms
17,308 KB
testcase_66 AC 34 ms
16,940 KB
testcase_67 AC 34 ms
16,788 KB
testcase_68 AC 2 ms
4,376 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 2 ms
4,376 KB
testcase_71 AC 2 ms
4,376 KB
testcase_72 AC 2 ms
4,376 KB
testcase_73 AC 2 ms
4,380 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=601;
const int NLIMIT=600;
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