Submission #3454768


Source Code Expand

#include<cstdio>
#define maxn 200005
#define LL long long
int n,a[maxn],l[maxn],r[maxn],st[maxn],tp;
LL ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		while(tp&&a[st[tp]]>=a[i]) tp--;
		l[i]=st[tp]; st[++tp]=i;
	}
	tp=0; st[0]=n+1;
	for(int i=n;i;i--)
	{
		while(tp&&a[st[tp]]>a[i]) tp--;
		r[i]=st[tp]; st[++tp]=i;
	}
	for(int i=1;i<=n;i++) ans+=1ll*a[i]*(i-l[i])*(r[i]-i);
	printf("%lld\n",ans);
}

Submission Info

Submission Time
Task B - Minimum Sum
User dogeding
Language C++14 (GCC 5.4.1)
Score 400
Code Size 481 Byte
Status AC
Exec Time 25 ms
Memory 3328 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:8:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:9:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
                                         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 21 ms 3328 KB
corner1 AC 21 ms 3328 KB
corner2 AC 1 ms 128 KB
corner3 AC 23 ms 2944 KB
example0 AC 1 ms 128 KB
example1 AC 1 ms 128 KB
example2 AC 1 ms 128 KB
maxrand0 AC 25 ms 2560 KB
maxrand1 AC 25 ms 2560 KB
maxrand2 AC 25 ms 2560 KB
rand0 AC 1 ms 128 KB
rand1 AC 1 ms 128 KB
rand2 AC 1 ms 128 KB