Submission #1828637
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; typedef long long ll; const int MAXN = 2*1e5 + 10; int v[MAXN],antes[MAXN],depois[MAXN],n; long long resposta; int main(){ stack<ii> pilha; cin.tie(0);ios_base::sync_with_stdio(0); cin >> n; v[0] = v[n+1] = -1; for(int i = 1;i<=n;i++){ cin >> v[i]; } pilha.push(ii(-1,0)); for(int i = 1;i<=n+1;i++){ ii davez = ii(v[i],i); while(pilha.top() > davez){ //printf("Depois de %d eh %d\n",pilha.top().second,i); depois[pilha.top().second] = i; pilha.pop(); } antes[i] = pilha.top().second; pilha.push(davez); } for(int i = 1;i<=n;i++){ antes[i]++; depois[i]--; int esq = abs(i - antes[i]) + 1; int dir = abs(depois[i] - i) + 1; resposta += 1LL*esq*dir*v[i]; } cout << resposta << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | IvanCarvalho |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 843 Byte |
Status | AC |
Exec Time | 22 ms |
Memory | 3640 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 | 21 ms | 3640 KB |
corner1 | AC | 19 ms | 2560 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 21 ms | 3228 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 21 ms | 2560 KB |
maxrand1 | AC | 22 ms | 2560 KB |
maxrand2 | AC | 22 ms | 2560 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |