QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153577#5500. BarsKnightWA 248ms5968kbC++14599b2023-08-30 11:48:402023-08-30 11:48:41

Judging History

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

  • [2023-08-30 11:48:41]
  • 评测
  • 测评结果:WA
  • 用时:248ms
  • 内存:5968kb
  • [2023-08-30 11:48:40]
  • 提交

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],stk[N],tt;
int V(int x,int y){
    return abs(x-y)*(a[x]+a[y]);
}
signed main(){
	scanf("%d",&T);
	while(T--){
	    tt=0;
	    scanf("%d",&n);
	    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	    stk[++tt]=1;int ans=0;
	    for(int i=2;i<=n;i++){
	        if(tt>1&&V(stk[tt-1],stk[tt])+V(i,stk[tt])<=V(stk[tt-1],i)) tt--;
	        stk[++tt]=i;
	    }
	    for(int i=2;i<=tt;i++) ans+=V(stk[i-1],stk[i]);
	    printf("%d\n",ans);
	}
    return 0;   
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

33
29

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 248ms
memory: 5960kb

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
1780030461
1914439249
362351966
-614827159
68006531
1498223757
-717454237
1525894986
1899874181
-760533029
-1466581783
1294997603
978601897
-780096250
1541377178
685056840
-1897846270
1218032176
139657000
935124636
-1166898973
580095360
2095057071
2067565728
295427888
1887201945
2081426718
106...

result:

wrong answer 3rd lines differ - expected: '382465638565', found: '1780030461'