結果
| 問題 |
No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
|
| コンテスト | |
| ユーザー |
publfl
|
| 提出日時 | 2021-01-22 22:25:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 493 ms / 2,000 ms |
| コード長 | 2,317 bytes |
| コンパイル時間 | 785 ms |
| コンパイル使用メモリ | 57,536 KB |
| 実行使用メモリ | 29,776 KB |
| 最終ジャッジ日時 | 2024-12-28 02:39:29 |
| 合計ジャッジ時間 | 16,045 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 74 |
ソースコード
#include <stdio.h>
#include <algorithm>
#include <vector>
struct str{
long long int value;
long long int index1;
long long int index2;
};
std::vector<str> V1,V2;
bool operator<(str a, str b)
{
return a.value<b.value;
}
int x[610],y[610];
long long int MIN = -1, MAX = 1;
int main()
{
for(int i=1;i<=18;i++) MIN*=10, MAX*=10;
int a,b,c,d;
long long int e;
scanf("%d%d%d%d%lld",&a,&b,&c,&d,&e);
for(int i=1;i<=a;i++) scanf("%d",&x[i]);
for(int i=1;i<=b;i++) scanf("%d",&y[i]);
for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) V1.push_back({x[i]*y[j],x[i],y[j]});
for(int i=1;i<=c;i++) scanf("%d",&x[i]);
for(int i=1;i<=d;i++) scanf("%d",&y[i]);
for(int i=1;i<=c;i++) for(int j=1;j<=d;j++) V2.push_back({x[i]*y[j],x[i],y[j]});
std::sort(V1.begin(),V1.end());
std::sort(V2.begin(),V2.end());
long long int min = MIN, max = MAX;
long long int ans = MAX;
while(min<=max)
{
long long int h = (min+max)/2;
//count val<=h
int ind = 0;
int control = 0;
long long int sum = 0;
for(int i=0;i<V1.size();i++)
{
if(V1[i].value<=0)
{
if(V1[i].value*V2[0].value<=h) sum += V2.size();
else if(V1[i].value*V2.back().value>h);
else
{
while(ind>=0&&V1[i].value*V2[ind].value<=h) ind--;
while(ind<V2.size()&&V1[i].value*V2[ind].value>h) ind++;
sum += (V2.size()-ind);
}
}
else
{
if(V1[i].value*V2[0].value>h);
else if(V1[i].value*V2.back().value<=h) sum += V2.size();
else
{
while(ind<V2.size()&&V1[i].value*V2[ind].value<=h) ind++;
while(ind>=0&&V1[i].value*V2[ind].value>h) ind--;
sum += (ind+1);
}
}
}
if(sum>=e)
{
ans = h;
max = h-1;
}
else min = h+1;
}
printf("%lld\n",ans);
for(int i=0;i<V1.size();i++)
{
if(V1[i].value==0)
{
if(ans==0)
{
printf("%lld %lld ",V1[i].index1,V1[i].index2);
printf("%lld %lld",V2[0].index1,V2[0].index2);
return 0;
}
else continue;
}
if(ans%(V1[i].value)==0)
{
long long int t = (ans)/(V1[i].value);
int min = 0, max = V2.size()-1;
while(min<=max)
{
int h = (min+max)/2;
if(V2[h].value==t)
{
printf("%lld %lld ",V1[i].index1,V1[i].index2);
printf("%lld %lld",V2[h].index1,V2[h].index2);
return 0;
}
else if(V2[h].value<t) min = h+1;
else max = h-1;
}
}
}
}
publfl