Submission #416633

# Submission time Handle Problem Language Result Execution time Memory
416633 2021-06-02T17:29:42 Z parsabahrami Liteh and Newfiteh (INOI20_litehfiteh) C++17
100 / 100
182 ms 142664 KB
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 1e5 + 10, MOD = 1e9 + 7;
int dp[19][19][N], A[N], pd[N], n;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) 
        scanf("%d", &A[i]);
    for (int i = 1; i <= n; i++) if (A[i] >= 19) return !printf("-1\n");
    for (int i = 0; i < 19; i++) 
        for (int j = 0; j < 19; j++) 
            for (int k = 0; k < N; k++) dp[i][j][k] = MOD;
    for (int i = 1; i <= n; i++) {
        dp[A[i]][0][i] = 0;
        if (A[i]) dp[A[i] - 1][0][i] = 1;
    }
    for (int l = 1; l < 19; l++) {
        for (int j = 0; j < 19; j++) {
            for (int i = 1; i <= n; i++) {
                if (i + (1 << l) > n + 1) continue;
                dp[j][l][i] = dp[j][l - 1][i] + dp[j][l - 1][i + (1 << (l - 1))];
                if (dp[j][l][i] > MOD) dp[j][l][i] = MOD;
                if (j + 1 < 19) {
                    dp[j][l][i] = min(dp[j][l][i], dp[j + 1][l - 1][i] + dp[j + 1][l - 1][i + (1 << (l - 1))] + 1);
                }
            }
        }
    }
   
    pd[0] = 0;
    for (int i = 1; i <= n; i++) {
        int pw = 0;
        pd[i] = MOD;
        for (; i - (1 << pw) >= 0; pw++) {
            pd[i] = min(pd[i], pd[i - (1 << pw)] + dp[0][pw][i - (1 << pw) + 1]);
        }
    }
    printf("%d\n", pd[n] >= MOD ? -1 : pd[n]);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 78 ms 141600 KB Output is correct
2 Correct 74 ms 141520 KB Output is correct
3 Correct 74 ms 141560 KB Output is correct
4 Correct 74 ms 141552 KB Output is correct
5 Correct 73 ms 141496 KB Output is correct
6 Correct 74 ms 141508 KB Output is correct
7 Correct 74 ms 141508 KB Output is correct
8 Correct 77 ms 141476 KB Output is correct
9 Correct 79 ms 141588 KB Output is correct
10 Correct 74 ms 141476 KB Output is correct
11 Correct 75 ms 141688 KB Output is correct
12 Correct 73 ms 141560 KB Output is correct
13 Correct 73 ms 141500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 141600 KB Output is correct
2 Correct 74 ms 141520 KB Output is correct
3 Correct 74 ms 141560 KB Output is correct
4 Correct 74 ms 141552 KB Output is correct
5 Correct 73 ms 141496 KB Output is correct
6 Correct 74 ms 141508 KB Output is correct
7 Correct 74 ms 141508 KB Output is correct
8 Correct 77 ms 141476 KB Output is correct
9 Correct 79 ms 141588 KB Output is correct
10 Correct 74 ms 141476 KB Output is correct
11 Correct 75 ms 141688 KB Output is correct
12 Correct 73 ms 141560 KB Output is correct
13 Correct 73 ms 141500 KB Output is correct
14 Correct 72 ms 141524 KB Output is correct
15 Correct 75 ms 141592 KB Output is correct
16 Correct 76 ms 141548 KB Output is correct
17 Correct 72 ms 141508 KB Output is correct
18 Correct 73 ms 141536 KB Output is correct
19 Correct 75 ms 141588 KB Output is correct
20 Correct 82 ms 141768 KB Output is correct
21 Correct 84 ms 141584 KB Output is correct
22 Correct 168 ms 142600 KB Output is correct
23 Correct 11 ms 972 KB Output is correct
24 Correct 177 ms 142500 KB Output is correct
25 Correct 74 ms 141532 KB Output is correct
26 Correct 76 ms 141588 KB Output is correct
27 Correct 73 ms 141544 KB Output is correct
28 Correct 76 ms 141520 KB Output is correct
29 Correct 82 ms 141636 KB Output is correct
30 Correct 87 ms 141620 KB Output is correct
31 Correct 84 ms 141564 KB Output is correct
32 Correct 83 ms 141636 KB Output is correct
33 Correct 168 ms 142520 KB Output is correct
34 Correct 174 ms 142616 KB Output is correct
35 Correct 176 ms 142532 KB Output is correct
36 Correct 167 ms 142504 KB Output is correct
37 Correct 169 ms 142660 KB Output is correct
38 Correct 176 ms 142528 KB Output is correct
39 Correct 172 ms 142632 KB Output is correct
40 Correct 168 ms 142532 KB Output is correct
41 Correct 182 ms 142664 KB Output is correct
42 Correct 171 ms 142556 KB Output is correct
43 Correct 168 ms 142532 KB Output is correct
44 Correct 175 ms 142552 KB Output is correct
45 Correct 170 ms 142476 KB Output is correct
46 Correct 177 ms 142552 KB Output is correct
47 Correct 139 ms 142148 KB Output is correct
48 Correct 147 ms 142292 KB Output is correct
49 Correct 159 ms 142368 KB Output is correct
50 Correct 174 ms 142496 KB Output is correct
51 Correct 86 ms 141628 KB Output is correct
52 Correct 176 ms 142556 KB Output is correct