Submission #905115
Source Code Expand
#include <bits/stdc++.h> #define PB push_back #define MP make_pair #define F first #define S second #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #ifdef _DEBUG_ #define debug(...) printf(__VA_ARGS__) #else #define debug(...) (void)0 #endif using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef vector<int> VI; const int N_MAX = 2e5+10; int arr[N_MAX]; int main() { int n; scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", arr+i); ll ans=0; stack<PII> stk; for(int i=n; i>=0; i--) { while(!stk.empty() && arr[i] < stk.top().F) { PII p = stk.top(); stk.pop(); int head = p.S-i; int tail = stk.empty() ? n-p.S+1 : stk.top().S-p.S; ans += 1ll*tail*head*p.F; } stk.push(MP(arr[i], i)); } printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | yangerma |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 846 Byte |
Status | AC |
Exec Time | 26 ms |
Memory | 2688 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:23:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:25:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", arr+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 | 23 ms | 1024 KB |
corner1 | AC | 26 ms | 2688 KB |
corner2 | AC | 2 ms | 256 KB |
corner3 | AC | 25 ms | 1792 KB |
example0 | AC | 3 ms | 256 KB |
example1 | AC | 2 ms | 256 KB |
example2 | AC | 2 ms | 256 KB |
maxrand0 | AC | 25 ms | 1024 KB |
maxrand1 | AC | 25 ms | 1024 KB |
maxrand2 | AC | 25 ms | 1024 KB |
rand0 | AC | 3 ms | 256 KB |
rand1 | AC | 3 ms | 256 KB |
rand2 | AC | 2 ms | 256 KB |