Submission #1814892
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int NMAX = 200005; long long n, a[NMAX], L[NMAX], R[NMAX], st[NMAX]; int main(){ //freopen("input.txt","r", stdin); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; int top = 0; st[0] = 0; for(int i = 1; i <= n; i++){ while(top > 0 && a[st[top]] >= a[i]) top--; L[i] = st[top] + 1; st[++top] = i; } top = 0, st[0] = n+1; for(int i = n; i >= 1; i--){ while(top > 0 && a[st[top]] >= a[i]) top--; R[i] = st[top] - 1; st[++top] = i; } long long res = 0, t1, t2; for(int i = 1; i <= n; i++){ t1 = i-L[i]; t2 = R[i] - i; res += (t1 + t2 + 1 +t1*t2)*a[i]; } cout << res; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | vjudge2 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 755 Byte |
Status | AC |
Exec Time | 64 ms |
Memory | 6528 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | 60 ms | 6528 KB |
corner1 | AC | 60 ms | 6528 KB |
corner2 | AC | 2 ms | 4352 KB |
corner3 | AC | 63 ms | 5760 KB |
example0 | AC | 2 ms | 4352 KB |
example1 | AC | 2 ms | 4352 KB |
example2 | AC | 2 ms | 4352 KB |
maxrand0 | AC | 63 ms | 4992 KB |
maxrand1 | AC | 64 ms | 4992 KB |
maxrand2 | AC | 64 ms | 4992 KB |
rand0 | AC | 2 ms | 4352 KB |
rand1 | AC | 3 ms | 4352 KB |
rand2 | AC | 2 ms | 4352 KB |