結果
問題 | No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩 |
ユーザー | 👑 Nachia |
提出日時 | 2021-01-22 22:37:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 449 ms / 2,000 ms |
コード長 | 1,990 bytes |
コンパイル時間 | 2,623 ms |
コンパイル使用メモリ | 202,924 KB |
最終ジャッジ日時 | 2025-01-18 04:52:06 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
ソースコード
#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; }