Submission #1438760


Source Code Expand

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}

typedef struct{
	int top;
	int *data;
}Stack;
void init(Stack *s,int size){
	s->data=(int*)calloc(size,sizeof(int));
	s->top=0;
	return;
}
void push(Stack *t,int a){
	t->data[t->top++]=a;
	return;
}
int pop(Stack *t){
	return t->data[--t->top];
}
int a[200000];
int l[200000],r[200000];
int main(void)
{
	int n,i;
	ll ans=0;
	Stack s;
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d",&a[i]);
	init(&s,n);
	FOR(i,0,n){
		while(s.top&&a[s.data[s.top-1]]>a[i]) s.top--;
		if(!s.top) l[i]=-1;
		else l[i]=s.data[s.top-1];
		push(&s,i);
	}
	s.top=0;
	for(i=n-1;i>=0;i--){
		while(s.top&&a[s.data[s.top-1]]>a[i]) s.top--;
		if(!s.top) r[i]=n;
		else r[i]=s.data[s.top-1];
		push(&s,i);
	}
	FOR(i,0,n) ans+=(ll)a[i]*(i-l[i])*(r[i]-i);
	printf("%lld\n",ans);
	return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User trainstation
Language C (GCC 5.4.1)
Score 400
Code Size 1208 Byte
Status AC
Exec Time 28 ms
Memory 3328 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:40:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ^
./Main.c:41:13: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  FOR(i,0,n) 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 23 ms 3328 KB
corner1 AC 23 ms 3328 KB
corner2 AC 1 ms 128 KB
corner3 AC 25 ms 3328 KB
example0 AC 1 ms 128 KB
example1 AC 1 ms 128 KB
example2 AC 1 ms 128 KB
maxrand0 AC 28 ms 3328 KB
maxrand1 AC 27 ms 3328 KB
maxrand2 AC 27 ms 3328 KB
rand0 AC 1 ms 128 KB
rand1 AC 1 ms 128 KB
rand2 AC 1 ms 128 KB