Submission #600562

# Submission time Handle Problem Language Result Execution time Memory
600562 2022-07-21T05:00:03 Z 반딧불(#8467) JOI15_building3 (JOI15_building3) C++14
100 / 100
108 ms 8272 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int arr[1000002];
bool isBad[1000002];
int badSum[1000002];
ll ans;

void checkBad(){
    int mx = 0;
    for(int i=1; i<n; i++){
        if(mx+2 < arr[i]){
            puts("0");
            exit(0);
        }
        if(mx+1 < arr[i]) isBad[i] = true;
        mx = max(mx, arr[i]);
        badSum[i] = badSum[i-1] + isBad[i];
    }
}

void solveIfNone(){
    int mx = 0;
    for(int i=1; i<n; i++){
        mx = max(mx, arr[i]);
        ans += mx + 1 - (1 <= arr[i+1] && arr[i+1] <= mx+1);
    }
    printf("%lld", ans);
    exit(0);
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<n; i++) scanf("%d", &arr[i]);
    checkBad();
    if(!badSum[n-1]) solveIfNone();
    if(badSum[n-1] >= 2){
        puts("0");
        return 0;
    }
    int key = 0, mx = 0;
    for(int i=1; i<=n; i++){
        if(isBad[i]){
            assert(mx+2 == arr[i]);
            key = arr[i]-1;
            mx = 0;
            for(int j=1; j<=i; j++){
                if(mx+1 >= key) ans++;
                mx = max(mx, arr[j]);
            }
            printf("%lld", ans);
            return 0;
        }
        mx = max(mx, arr[i]);
    }
    return 1;
}

Compilation message

building3.cpp: In function 'int main()':
building3.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
building3.cpp:38:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     for(int i=1; i<n; i++) scanf("%d", &arr[i]);
      |                            ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 75 ms 8240 KB Output is correct
22 Correct 77 ms 7728 KB Output is correct
23 Correct 80 ms 8140 KB Output is correct
24 Correct 93 ms 8148 KB Output is correct
25 Correct 87 ms 8128 KB Output is correct
26 Correct 87 ms 8152 KB Output is correct
27 Correct 108 ms 8192 KB Output is correct
28 Correct 93 ms 8204 KB Output is correct
29 Correct 70 ms 8200 KB Output is correct
30 Correct 76 ms 8244 KB Output is correct
31 Correct 83 ms 8200 KB Output is correct
32 Correct 86 ms 8200 KB Output is correct
33 Correct 86 ms 8212 KB Output is correct
34 Correct 83 ms 8172 KB Output is correct
35 Correct 100 ms 8272 KB Output is correct