Submission #1258754


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

const int DIM = 1e1 + 5;

vector<int> stk;
int arr[DIM], lef[DIM], rig[DIM];

int main( void ) {
    
    int n;
    cin >> n;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    stk.assign( 1, 0 );
    for( int i = 1; i <= n; i ++ ) {
        while( arr[i] <= arr[stk.back()] )
            stk.pop_back();
        
        lef[i] = stk.back() + 1;
        stk.push_back( i );
    }
    
    stk.assign( 1, n + 1 );
    for( int i = n; i >= 1; i -- ) {
        while( arr[i] <= arr[stk.back()] )
            stk.pop_back();
        
        rig[i] = stk.back() - 1;
        stk.push_back( i );
    }
    
    long long ans = 0;
    for( int i = 1; i <= n; i ++ )
        ans += 1LL * arr[i] * ( i - lef[i] + 1 ) * ( rig[i] - i + 1 );
    
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User EmanuelNrx
Language C++14 (GCC 5.4.1)
Score 0
Code Size 886 Byte
Status RE
Exec Time 113 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 5
RE × 8
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 RE 113 ms 256 KB
corner1 RE 96 ms 256 KB
corner2 AC 1 ms 256 KB
corner3 RE 96 ms 256 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 RE 96 ms 256 KB
maxrand1 RE 96 ms 256 KB
maxrand2 RE 96 ms 256 KB
rand0 RE 96 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 RE 98 ms 256 KB