Submission #1354619


Source Code Expand

#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 1<<17;
const int MM = 1000000007;

struct UF{
	int t[MX], c[MX];
	void clear(){
		for(int i = 0; i < MX; i++) t[i] = i, c[i] = 1;
	}
	int find(int a){ return t[a] == a ? a : t[a] = find(t[a]); }
	int merge(int a, int b){
		a = find(a), b = find(b);
		t[a] = b, c[b] += c[a];
	}
} uf;

int D[MX], E[MX];
int N;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", D+i), E[i] = i;
	sort(E+1, E+N+1, [](int l, int r){ return D[l] > D[r]; });
	uf.clear();
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		int c = E[i];
		int a = 1, b = 1;
		if( c >= 2 && D[c-1] > D[c] ) a += uf.c[uf.find(c-1)], uf.merge(c, c-1);
		if( c < N && D[c+1] > D[c] ) b += uf.c[uf.find(c+1)], uf.merge(c, c+1);
		ans += (ll)a * b * D[c];
	}
	printf("%lld\n", ans);
}

Submission Info

Submission Time
Task B - Minimum Sum
User zigui
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1262 Byte
Status RE
Exec Time 2103 ms
Memory 2304 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:45:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:46:56: 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", D+i), E[i] = i;
                                                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 7
WA × 2
TLE × 1
RE × 3
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 TLE 2103 ms 1536 KB
corner1 WA 26 ms 2304 KB
corner2 AC 2 ms 1280 KB
corner3 WA 32 ms 2304 KB
example0 AC 2 ms 1280 KB
example1 AC 2 ms 1280 KB
example2 AC 2 ms 1280 KB
maxrand0 RE 1770 ms 2304 KB
maxrand1 RE 905 ms 2304 KB
maxrand2 RE 904 ms 2304 KB
rand0 AC 2 ms 1280 KB
rand1 AC 2 ms 1280 KB
rand2 AC 2 ms 1280 KB