結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2020-11-01 16:11:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,262 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 86,452 KB
実行使用メモリ 9,608 KB
最終ジャッジ日時 2023-08-27 16:14:21
合計ジャッジ時間 20,071 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 RE -
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
testcase_33 WA -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
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 1 ms
4,376 KB
testcase_69 AC 1 ms
4,380 KB
testcase_70 AC 1 ms
4,376 KB
testcase_71 AC 1 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=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;
  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());
  //二分探索。x 以下の要素が s 個以上になる最小の x が欲しい。
  //8.1*10^17 を包む値
  lint pass=1e18,fail=-1e18;
  while(pass-fail>1){
    lint mid=fail+(pass-fail)/2;
    lint count=0;
    rep(i,m*n){
      lint div=lat[i];
      if(div==0)count+=mid>=0?k*l:0;
      else if(div>0){
        lint q=quo(mid,div);
        count+=upper_bound(frm.begin(),frm.end(),pli(q,1e9))-frm.begin();
      }else{
        lint q=quo(-mid-div-1,-div);
        count+=frm.end()-lower_bound(frm.begin(),frm.end(),pli(q,-1));
      }
    }
    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/k;
      int j1=frm[idx].second%k;
      cout<<a[j0]<<" "<<b[j1]<<" "<<c[i0]<<" "<<d[i1]<<endl;
      return 0;
    }
  }
  assert(0);
}
0