QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243490#5517. Adjacent Product SumGeospiza#WA 21ms5016kbC++141.5kb2023-11-08 13:12:572023-11-08 13:12:59

Judging History

你现在查看的是最新测评结果

  • [2023-11-08 13:12:59]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:5016kb
  • [2023-11-08 13:12:57]
  • 提交

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)
    {
        ans+=l.back()*r[0]+r.back()*l[0];
        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: 0ms
memory: 3748kb

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: 21ms
memory: 5016kb

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:

66606463164493966

result:

wrong answer 1st numbers differ - expected: '66608463123493911', found: '66606463164493966'