QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#198365#5500. Barsgrass8cow#TL 729ms10048kbC++14436b2023-10-03 13:23:442023-10-03 13:23:46

Judging History

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

  • [2023-10-03 13:23:46]
  • 评测
  • 测评结果:TL
  • 用时:729ms
  • 内存:10048kb
  • [2023-10-03 13:23:44]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,L[500100],sta[500100],top;ll a[500010],dp[500100];
void sol(){
	scanf("%d",&n);
	top=0;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),dp[i]=-1e18;
	dp[1]=0;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)
	dp[j]=max(dp[j],dp[i]+1ll*a[i]*j-1ll*a[j]*i);
	printf("%lld\n",1ll*dp[n]+1ll*n*a[n]-a[1]);
}
int main(){
	int T;cin>>T;while(T--)sol();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7888kb

input:

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

output:

33
29

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 729ms
memory: 10048kb

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
382465638565
663641330002
550288673161
458946673513
296420749955
875760099157
632854843886
586309163102
225238173690
716890380495
466644027129
283505446030
585094154153
201707398762
336548832140
483300272586
606382970973
587469399170
408018096564
827347820764
975377092201
925120038848
26408806...

result:

ok 10000 lines

Test #3:

score: -100
Time Limit Exceeded

input:

6
500000
287001636 204980186 997392401 188445265 873977784 672984447 520446063 460936121 420229946 413937980 95267858 869951831 87353679 843288346 375704325 376217775 66621398 502675506 854835633 99408891 880520553 944446461 690146628 632137514 179514334 551490018 981073461 196185611 719601446 93667...

output:


result: