Submission #1697893
Source Code Expand
#include "bits/stdc++.h" #define rep(i,n) for(int i=0;i<n;i++) #define ALL(v) (v).begin(),(v).end() typedef long long LL; const int INF = 1 << 25; const LL MOD = 1000000007LL; using namespace std; typedef pair<int, int> P; int a[200000]; int l[200000]; int r[200000]; int main() { stack<P> S1, S2; int N; cin >> N; rep(i, N) cin >> a[i]; S1.push(P(-1, -1)); for (int i = 0; i < N; i++) { while (S1.top().first > a[i]) { S1.pop(); } l[i] = i - S1.top().second; S1.push(P(a[i], i)); } S2.push(P(-1, N)); for (int i = N - 1; i >= 0; i--) { while (S2.top().first > a[i]) { S2.pop(); } r[i] = S2.top().second - i; S2.push(P(a[i], i)); } LL sum = 0; rep(i, N) { sum += (LL)a[i] * l[i] * r[i]; } cout << sum << endl; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | Div9851 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 786 Byte |
Status | AC |
Exec Time | 69 ms |
Memory | 4224 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 | 64 ms | 4224 KB |
corner1 | AC | 64 ms | 4224 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 65 ms | 3252 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 65 ms | 2560 KB |
maxrand1 | AC | 69 ms | 2560 KB |
maxrand2 | AC | 65 ms | 2688 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |