Submission #904978
Source Code Expand
#include <bits/stdc++.h> using namespace std; int n,m,i,j,a,b[200200],l[200200],r[200200]; long long res; int main() { scanf("%d",&n); for (i=1; i<=n; i++) { scanf("%d",&a); b[a]=i; } for (i=n; i>0; i--) { j=b[i]; l[j]=r[j]=j; if (j>1 && r[j-1]!=0) l[j]=l[j-1]; if (j<n && l[j+1]!=0) r[j]=r[j+1]; l[r[j]]=l[j]; r[l[j]]=r[j]; res+=(j-l[j]+1LL)*(r[j]-j+1LL)*i; } printf("%lld\n",res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | Ra16bit |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 467 Byte |
Status | AC |
Exec Time | 28 ms |
Memory | 2560 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:6:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:8:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&a); ^
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 | 25 ms | 2560 KB |
corner1 | AC | 25 ms | 2560 KB |
corner2 | AC | 3 ms | 256 KB |
corner3 | AC | 26 ms | 2560 KB |
example0 | AC | 3 ms | 256 KB |
example1 | AC | 3 ms | 256 KB |
example2 | AC | 2 ms | 256 KB |
maxrand0 | AC | 28 ms | 2560 KB |
maxrand1 | AC | 28 ms | 2560 KB |
maxrand2 | AC | 28 ms | 2560 KB |
rand0 | AC | 3 ms | 256 KB |
rand1 | AC | 2 ms | 256 KB |
rand2 | AC | 3 ms | 256 KB |