Submission #904965


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("%d\n",res);
  return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User Ra16bit
Language C++14 (GCC 5.4.1)
Score 0
Code Size 465 Byte
Status WA
Exec Time 28 ms
Memory 2688 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:20:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
   printf("%d\n",res);
                    ^
./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 0 / 400
Status
AC × 3
AC × 7
WA × 6
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 WA 25 ms 2560 KB
corner1 WA 25 ms 2560 KB
corner2 AC 3 ms 256 KB
corner3 WA 26 ms 2560 KB
example0 AC 3 ms 256 KB
example1 AC 3 ms 256 KB
example2 AC 3 ms 256 KB
maxrand0 WA 28 ms 2560 KB
maxrand1 WA 28 ms 2688 KB
maxrand2 WA 28 ms 2560 KB
rand0 AC 3 ms 256 KB
rand1 AC 2 ms 256 KB
rand2 AC 3 ms 256 KB