QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#674234 | #5754. Minimum Scalar Product | Hog_Dawa_IOI | 0 | 2ms | 3824kb | C++14 | 1.4kb | 2024-10-25 14:40:20 | 2024-10-25 14:40:20 |
answer
#include<queue>
#include<cstdio>
using namespace std;
priority_queue<long long,vector<long long>,less<long long> >zhea,zheb;
priority_queue<long long,vector<long long>,greater<long long> >fua,fub;
long long t,n,sr,zera,zerb;long long sum;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n),sum=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&sr);
if(sr<0) fua.push(sr);
else if(sr>0) zhea.push(sr);
else zera++;
}
for(int i=1;i<=n;i++)
{
scanf("%lld",&sr);
if(sr<0) fub.push(sr);
else if(sr>0) zheb.push(sr);
else zerb++;
}
while((!fua.empty())&&(!zheb.empty()))
{
long long a=fua.top(),b=zheb.top();
fua.pop(),zheb.pop(),sum+=a*b;
}
while((!zhea.empty())&&(!fub.empty()))
{
long long a=zhea.top(),b=fub.top();
zhea.pop(),fub.pop(),sum+=a*b;
}
// 1.fua+zhea+zerb
// 2.fua+fub(+zerb)(+zera)
while(zera>0)
{
long long fu=(fub.empty()?0:-fub.top()),
zhe=(zheb.empty()?0:zheb.top());
if(fu>zhe) zera--,fub.pop();
else if(fu<zhe||fu==zhe&&fu!=0)
zera--,zheb.pop();
}
while(zerb>0)
{
long long fu=(fua.empty()?0:-fua.top()),
zhe=(zhea.empty()?0:zhea.top());
if(fu>zhe) zerb--,fua.pop();
else if(fu<zhe||fu==zhe&&fu!=0)
zerb--,zhea.pop();
}
while(!fua.empty()) sum+=fua.top()
*fub.top(),fua.pop(),fub.pop();
while(!zhea.empty()) sum+=zhea.top()
*zheb.top(),zhea.pop(),zheb.pop();
printf("%lld\n",sum);
}
}
詳細信息
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
1000 3 -5 3 1 1 4 -2 5 3 1 5 2 4 0 1 1 0 1 8 372 887 -30 -600 -63 -947 526 307 -430 -426 -168 -538 350 515 988 299 7 891 -7 -475 163 495 -52 305 -381 248 -2 458 -114 -44 -47 1 -399 -394 8 49 31 -847 -310 348 -746 244 -907 11 -952 -772 741 -655 770 283 393 4 850 251 209 -896 237 669 884 -733 3 604 -8...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 3824kb
input:
10 800 -99991 99994 99990 -99996 -99997 -99995 -99992 99996 -99994 -99998 99995 -99995 99998 99990 99995 -99994 -100000 -99993 -99992 -99994 99993 99997 -99998 99998 99995 99999 99999 -99994 -99994 99996 99996 -99995 -99990 99996 100000 -99997 99991 99998 99991 99995 -99995 -99991 99992 -100000 -999...
output:
-7679252425391 7999194128280 -2402011240562 -1667584048494 -3547072388917 -1565675624900 -3107736222915 -3683923332973 -485263078480 -2737428394406
result:
wrong answer 1st lines differ - expected: 'Case #1: -7679252425391', found: '-7679252425391'