Submission #1354612
Source Code Expand
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n, a[200005], cur, ans; vector<ll> st; int main() { scanf("%lld",&n); for(ll i=1;i<=n;i++) { scanf("%lld",&a[i]); } st.push_back(0); for(ll i=1;i<=n;i++) { while(!st.empty()) { if(a[st.back()] >= a[i]) { ll T = st.back(); st.pop_back(); cur -= (T - st.back()) * a[T]; } else break; } cur += (i - st.back()) * a[i]; st.push_back(i); ans += cur; } printf("%lld\n",ans); }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | khsoo01 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 506 Byte |
Status | AC |
Exec Time | 25 ms |
Memory | 3956 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:10:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&n); ^ ./Main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&a[i]); ^
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 | 24 ms | 3956 KB |
corner1 | AC | 23 ms | 1792 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 25 ms | 2936 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 24 ms | 1792 KB |
maxrand1 | AC | 24 ms | 1792 KB |
maxrand2 | AC | 23 ms | 1792 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |