結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 👑 NachiaNachia
提出日時 2021-01-22 22:37:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 415 ms / 2,000 ms
コード長 1,990 bytes
コンパイル時間 2,378 ms
コンパイル使用メモリ 209,140 KB
実行使用メモリ 23,948 KB
最終ジャッジ日時 2023-08-27 20:37:10
合計ジャッジ時間 19,522 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 9 ms
4,376 KB
testcase_20 AC 21 ms
4,376 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 12 ms
4,376 KB
testcase_23 AC 18 ms
4,380 KB
testcase_24 AC 16 ms
4,380 KB
testcase_25 AC 19 ms
4,380 KB
testcase_26 AC 21 ms
4,376 KB
testcase_27 AC 13 ms
4,380 KB
testcase_28 AC 142 ms
11,376 KB
testcase_29 AC 128 ms
7,952 KB
testcase_30 AC 117 ms
7,948 KB
testcase_31 AC 138 ms
12,352 KB
testcase_32 AC 148 ms
14,280 KB
testcase_33 AC 108 ms
7,960 KB
testcase_34 AC 155 ms
13,500 KB
testcase_35 AC 195 ms
13,028 KB
testcase_36 AC 286 ms
16,332 KB
testcase_37 AC 61 ms
6,088 KB
testcase_38 AC 146 ms
9,188 KB
testcase_39 AC 93 ms
7,760 KB
testcase_40 AC 111 ms
7,956 KB
testcase_41 AC 164 ms
9,696 KB
testcase_42 AC 285 ms
15,956 KB
testcase_43 AC 163 ms
14,120 KB
testcase_44 AC 209 ms
13,976 KB
testcase_45 AC 161 ms
10,368 KB
testcase_46 AC 148 ms
12,480 KB
testcase_47 AC 101 ms
7,152 KB
testcase_48 AC 271 ms
23,564 KB
testcase_49 AC 187 ms
23,172 KB
testcase_50 AC 286 ms
22,752 KB
testcase_51 AC 241 ms
23,076 KB
testcase_52 AC 235 ms
22,508 KB
testcase_53 AC 415 ms
23,328 KB
testcase_54 AC 389 ms
22,448 KB
testcase_55 AC 412 ms
22,380 KB
testcase_56 AC 397 ms
22,968 KB
testcase_57 AC 267 ms
23,948 KB
testcase_58 AC 205 ms
22,768 KB
testcase_59 AC 205 ms
22,828 KB
testcase_60 AC 210 ms
22,792 KB
testcase_61 AC 211 ms
21,848 KB
testcase_62 AC 208 ms
23,348 KB
testcase_63 AC 119 ms
22,916 KB
testcase_64 AC 120 ms
22,832 KB
testcase_65 AC 117 ms
22,044 KB
testcase_66 AC 120 ms
23,020 KB
testcase_67 AC 120 ms
22,636 KB
testcase_68 AC 1 ms
4,376 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 2 ms
4,380 KB
testcase_71 AC 1 ms
4,376 KB
testcase_72 AC 2 ms
4,376 KB
testcase_73 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N[4];
LL S;
int A[4][600];
vector<pair<LL,int>> X;
vector<pair<LL,int>> Y;

const LL INF=1ll<<60;

pair<LL,pair<int,int>> constructans(int xp,int yp){
  return {X[xp].first*Y[yp].first,{X[xp].second,Y[yp].second}};
}

// x 以下を数える
pair<LL,pair<int,int>> search(LL x){
  LL cnt=0;
  pair<LL,pair<int,int>> ans={INF,{-1,-1}};
  if(x>=0){
    int j=Y.size(), k=Y.size();
    rep(i,X.size()){
      if(X[i].first<0){
        while((j>0)?X[i].first*Y[j-1].first<=x:false) j--;
        cnt+=Y.size()-j;
        if(j>0) ans=min(ans,constructans(i,j-1));
      }
      else if(X[i].first>0){
        while((k>0)?X[i].first*Y[k-1].first>x:false) k--;
        cnt+=k;
        if(k<Y.size()) ans=min(ans,constructans(i,k));
      }
      else{
        cnt+=Y.size();
      }
    }
  }
  else{
    int j=0, k=0;
    rep(i,X.size()){
      if(X[i].first<0){
        while((j<Y.size())?X[i].first*Y[j].first>x:false) j++;
        cnt+=Y.size()-j;
        if(j>0) ans=min(ans,constructans(i,j-1));
      }
      else if(X[i].first>0){
        while((k<Y.size())?X[i].first*Y[k].first<=x:false) k++;
        cnt+=k;
        if(k<Y.size()) ans=min(ans,constructans(i,k));
      }
      else{
        ans=min(ans,constructans(i,0));
      }
    }
  }
  ans.first=cnt;
  return ans;
}

int main() {
  rep(i,4) cin>>N[i]; cin>>S;
  rep(i,4) rep(j,N[i]) cin>>A[i][j];
  rep(i,N[0]) rep(j,N[1]) X.push_back({A[0][i]*A[1][j],i*600+j}); sort(X.begin(),X.end());
  rep(i,N[2]) rep(j,N[3]) Y.push_back({A[2][i]*A[3][j],i*600+j}); sort(Y.begin(),Y.end());
  LL l=-INF, r=INF; pair<int,int> ans;
  while(r-l>1){
    LL m=(l+r)/2;
    auto res=search(m);
    if(res.first<S){ l=m; ans=res.second; } else{ r=m; }
  }
  cout<<r<<endl;
  cout<<A[0][ans.first/600]<<" "<<A[1][ans.first%600]<<" "<<A[2][ans.second/600]<<" "<<A[3][ans.second%600]<<endl;
  return 0;
}
0