QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243502 | #5517. Adjacent Product Sum | Geospiza# | WA | 24ms | 4988kb | C++14 | 1.5kb | 2023-11-08 13:23:41 | 2023-11-08 13:23:42 |
Judging History
answer
//#pragma GCC optimize(3,"Ofast","inline")
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
#define Ma 1000005
#define G 3
#define pb push_back
#define L (1<<21)
#define all(x) x.begin(),x.end()
using namespace std;
ll n,m;
vector <ll> l,r;
bool cmp(ll x,ll y)
{
return x>y;
}
void sol()
{
l.clear(),r.clear();
cin>>n;
ll cnt=0;
for (ll i=1;i<=n;i++)
{
ll x;
cin>>x;
if (x>0)
l.pb(x);
else if (x<0)
r.pb(x);
else
cnt++;
}
sort(all(l),cmp),sort(all(r),cmp);
ll ans=0;
for (ll i=1;i<l.size();i++)
ans+=l[max(0ll,i-2)]*l[i];
for (ll i=1;i<r.size();i++)
ans+=r[max(0ll,i-2)]*r[i];
if (!l.size()||!r.size())
{
if (!l.size())
{
if (!cnt)
ans+=r.back()*r[r.size()-2];
}
else if (!r.size())
{
if (!cnt)
ans+=l.back()*l[l.size()-2];
}
printf("%lld\n",ans);
return;
}
else if (cnt==0)
{
ll pr=max(0ll,(ll)r.size()-2),pl=max(0ll,(ll)l.size()-2);
ans+=l.back()*r[pr]+r.back()*l[pl];
printf("%lld\n",ans);
}
else if (cnt==1)
{
ans+=l.back()*r.back();
printf("%lld\n",ans);
}
else
{
printf("%lld\n",ans);
}
return;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
ll tt=1;
cin>>tt;
while (tt--)
sol();
return 0;
}
/*500000 500000*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3844kb
input:
4 3 1 2 3 6 1 1 1 1 0 0 5 100000 100000 100000 100000 -100000 5 1 2 3 4 5
output:
11 3 10000000000 48
result:
ok 4 number(s): "11 3 10000000000 48"
Test #2:
score: -100
Wrong Answer
time: 24ms
memory: 4988kb
input:
1 200000 11009 633591 -419208 -664908 731171 -774644 -878270 656078 -38057 -220602 -897906 670165 -765931 -612936 -583782 -549624 -644245 137209 -983054 -110583 349193 699723 -412876 -417691 810865 -474314 -200632 570810 -283481 39600 20940 218215 -408751 -507326 -961614 600863 499517 -538207 767155...
output:
66607463124494047
result:
wrong answer 1st numbers differ - expected: '66608463123493911', found: '66607463124494047'