QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153550#5500. BarsKnightTL 2ms20408kbC++14686b2023-08-30 11:10:052023-08-30 11:10:06

Judging History

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

  • [2023-08-30 11:10:06]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:20408kb
  • [2023-08-30 11:10:05]
  • 提交

answer

#include<bits/stdc++.h> 
#define int long long
#define ll long long
using namespace std;
const int N=1e6+10;
int T,n,a[N],f[N],g[N];
signed main(){
	scanf("%d",&T);
	while(T--){
	    scanf("%d",&n);
	    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	    memset(f,0,sizeof(f));
	    memset(g,0,sizeof(g));
	    for(int i=2;i<=n;i++)
	        for(int j=1;j<i;j++) 
	            f[i]=max(f[i],f[j]+(i-j)*(a[i]+a[j]));
	    reverse(a+1,a+n+1);
	    for(int i=2;i<=n;i++)
	        for(int j=1;j<i;j++) 
	            g[i]=max(g[i],g[j]+(i-j)*(a[i]+a[j]));
	    int ans=0;
	    for(int i=1;i<=n;i++) ans=max(ans,f[i]+g[i]);
	    printf("%d\n",ans/2);
	}
    return 0;   
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 20408kb

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

33
29

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

10000
4
5 2 2 6
5
1 5 4 4 1
197
763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...

output:

33
29
213549221
-2078600878
532859273
-614827159
68006531
-413229227
1494651374
-2101356450
1899874298
-369157937
-1507408135
37604494
978601897
-156064150
1541383052
-2031031862
792582237
-941120382
-3796556
-1580867364
419516009
1702070208
2095057071
2067565728
200762466
-1832458261
1607194228
257...

result: