QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#674236 | #5754. Minimum Scalar Product | Hog_Dawa_IOI | 0 | 2ms | 3972kb | C++14 | 1.5kb | 2024-10-25 14:41:21 | 2024-10-25 14:41:22 |
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);
for(int ss=1;ss<=t;ss++)
{
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("Case #%d: %lld\n",ss,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:
Case #1: -25 Case #2: 6 Case #3: -2189090 Case #4: -647840 Case #5: 157206 Case #6: -2258343 Case #7: -1197662 Case #8: -678102 Case #9: -2052381 Case #10: -3313 Case #11: -1012446 Case #12: -2501491 Case #13: -2255469 Case #14: -2337367 Case #15: -149095 Case #16: -3202403 Case #17: -2351174 Case #...
result:
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 3972kb
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:
Case #1: -7679252425391 Case #2: 7999194128280 Case #3: -2402011240562 Case #4: -1667584048494 Case #5: -3547072388917 Case #6: -1565675624900 Case #7: -3107736222915 Case #8: -3683923332973 Case #9: -485263078480 Case #10: -2737428394406
result:
wrong answer 2nd lines differ - expected: 'Case #2: 7999194112308', found: 'Case #2: 7999194128280'