답안 #809045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
809045 2023-08-05T14:43:17 Z finn__ Tortoise (CEOI21_tortoise) C++17
48 / 100
274 ms 432584 KB
#include <bits/stdc++.h>
using namespace std;

constexpr size_t N = 301;

int32_t f[(N << 1) - 1][N][N], a[N], x[N], u[N], v[N];

int main()
{
    sizeof f;
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int32_t n, m = 0, last_playground = -1;
    cin >> n;

    int32_t sum_a = 0;
    for (size_t i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (a[i] > 0)
            x[m] = i, u[m] = last_playground, sum_a += a[i], ++m;
        else if (a[i] == -1)
            last_playground = i;
    }

    last_playground = n;
    for (size_t i = n - 1, j = m - 1; i < n; --i)
    {
        if (a[i] > 0)
            v[j] = last_playground, --j;
        else if (a[i] == -1)
            last_playground = i;
    }

    for (size_t i = 0; i < (N << 1) - 1; ++i)
        for (size_t j = 0; j < N; ++j)
            fill(f[i][j], f[i][j] + N, INT32_MIN);
    for (size_t i = 0; i < m; ++i)
        f[x[i]][i][0] = 0;

    int32_t ans = 0;
    for (int32_t i = 0; i < (n << 1) - 1; ++i)
        for (size_t j = 0; j < m; ++j)
        {
            for (size_t k = 0; k < a[x[j]] && k < n; ++k)
            {
                ans = max(ans, f[i][j][k] + (i <= (x[j] << 1)));

                if (i <= (x[j] << 1))
                {

                    // current shop
                    // preceding playground.
                    if (u[j] != -1 && i + ((x[j] - u[j]) << 1) < (n << 1) - 1)
                        f[i + ((x[j] - u[j]) << 1)][j][k + 1] = max(f[i + ((x[j] - u[j]) << 1)][j][k + 1], f[i][j][k] + 1);
                    //  next playground.
                    if (v[j] != n && i + ((v[j] - x[j]) << 1) < (n << 1) - 1)
                        f[i + ((v[j] - x[j]) << 1)][j][k + 1] = max(f[i + ((v[j] - x[j]) << 1)][j][k + 1], f[i][j][k] + 1);

                    // next shop
                    if (j + 1 < m)
                    {
                        // preceding playground
                        if (u[j] != -1 && i + (x[j] - u[j]) + (x[j + 1] - u[j]) < (n << 1) - 1)
                            f[i + (x[j] - u[j]) + (x[j + 1] - u[j])][j + 1][0] = max(f[i + (x[j] - u[j]) + (x[j + 1] - u[j])][j + 1][0], f[i][j][k] + 1);
                        // next playground
                        if (v[j] != n && i + (v[j] - x[j]) + abs(x[j + 1] - v[j]) < (n << 1) - 1)
                            f[i + (v[j] - x[j]) + abs(x[j + 1] - v[j])][j + 1][0] = max(f[i + (v[j] - x[j]) + abs(x[j + 1] - v[j])][j + 1][0], f[i][j][k] + 1);
                    }
                }
            }

            if (j + 1 < m)
                for (size_t k = 0; k <= a[x[j]] && k <= n; ++k)
                    if (i + x[j + 1] - x[j] < (n << 1) - 1)
                        f[i + x[j + 1] - x[j]][j + 1][0] = max(f[i + x[j + 1] - x[j]][j + 1][0], f[i][j][k]);
        }

    cout << sum_a - ans << '\n';
}

Compilation message

tortoise.cpp: In function 'int main()':
tortoise.cpp:10:5: warning: statement has no effect [-Wunused-value]
   10 |     sizeof f;
      |     ^~~~~~~~
tortoise.cpp:18:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   18 |     for (size_t i = 0; i < n; ++i)
      |                        ~~^~~
tortoise.cpp:28:41: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   28 |     for (size_t i = n - 1, j = m - 1; i < n; --i)
      |                                       ~~^~~
tortoise.cpp:39:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   39 |     for (size_t i = 0; i < m; ++i)
      |                        ~~^~~
tortoise.cpp:44:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   44 |         for (size_t j = 0; j < m; ++j)
      |                            ~~^~~
tortoise.cpp:46:34: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   46 |             for (size_t k = 0; k < a[x[j]] && k < n; ++k)
      |                                ~~^~~~~~~~~
tortoise.cpp:46:49: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   46 |             for (size_t k = 0; k < a[x[j]] && k < n; ++k)
      |                                               ~~^~~
tortoise.cpp:62:31: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   62 |                     if (j + 1 < m)
      |                         ~~~~~~^~~
tortoise.cpp:74:23: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   74 |             if (j + 1 < m)
      |                 ~~~~~~^~~
tortoise.cpp:75:38: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   75 |                 for (size_t k = 0; k <= a[x[j]] && k <= n; ++k)
      |                                    ~~^~~~~~~~~~
tortoise.cpp:75:54: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   75 |                 for (size_t k = 0; k <= a[x[j]] && k <= n; ++k)
      |                                                    ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 213400 KB Output is correct
2 Correct 89 ms 213356 KB Output is correct
3 Correct 88 ms 213388 KB Output is correct
4 Correct 88 ms 213328 KB Output is correct
5 Correct 89 ms 213384 KB Output is correct
6 Correct 87 ms 213324 KB Output is correct
7 Correct 89 ms 213372 KB Output is correct
8 Correct 90 ms 213376 KB Output is correct
9 Correct 90 ms 213368 KB Output is correct
10 Correct 88 ms 213348 KB Output is correct
11 Correct 89 ms 213420 KB Output is correct
12 Correct 88 ms 213368 KB Output is correct
13 Correct 89 ms 213348 KB Output is correct
14 Correct 91 ms 213356 KB Output is correct
15 Correct 88 ms 213300 KB Output is correct
16 Correct 90 ms 213424 KB Output is correct
17 Correct 92 ms 213324 KB Output is correct
18 Correct 89 ms 213348 KB Output is correct
19 Correct 89 ms 213368 KB Output is correct
20 Correct 88 ms 213392 KB Output is correct
21 Correct 90 ms 213336 KB Output is correct
22 Correct 92 ms 213400 KB Output is correct
23 Correct 90 ms 213304 KB Output is correct
24 Correct 89 ms 213388 KB Output is correct
25 Correct 96 ms 213328 KB Output is correct
26 Correct 94 ms 213312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 213400 KB Output is correct
2 Correct 89 ms 213356 KB Output is correct
3 Correct 88 ms 213388 KB Output is correct
4 Correct 88 ms 213328 KB Output is correct
5 Correct 89 ms 213384 KB Output is correct
6 Correct 87 ms 213324 KB Output is correct
7 Correct 89 ms 213372 KB Output is correct
8 Correct 90 ms 213376 KB Output is correct
9 Correct 90 ms 213368 KB Output is correct
10 Correct 88 ms 213348 KB Output is correct
11 Correct 89 ms 213420 KB Output is correct
12 Correct 88 ms 213368 KB Output is correct
13 Correct 89 ms 213348 KB Output is correct
14 Correct 91 ms 213356 KB Output is correct
15 Correct 88 ms 213300 KB Output is correct
16 Correct 90 ms 213424 KB Output is correct
17 Correct 92 ms 213324 KB Output is correct
18 Correct 89 ms 213348 KB Output is correct
19 Correct 89 ms 213368 KB Output is correct
20 Correct 88 ms 213392 KB Output is correct
21 Correct 90 ms 213336 KB Output is correct
22 Correct 92 ms 213400 KB Output is correct
23 Correct 90 ms 213304 KB Output is correct
24 Correct 89 ms 213388 KB Output is correct
25 Correct 96 ms 213328 KB Output is correct
26 Correct 94 ms 213312 KB Output is correct
27 Correct 94 ms 213384 KB Output is correct
28 Correct 96 ms 213412 KB Output is correct
29 Correct 111 ms 213416 KB Output is correct
30 Correct 98 ms 213412 KB Output is correct
31 Correct 113 ms 213360 KB Output is correct
32 Correct 93 ms 213384 KB Output is correct
33 Correct 94 ms 213308 KB Output is correct
34 Correct 93 ms 213320 KB Output is correct
35 Correct 93 ms 213420 KB Output is correct
36 Correct 94 ms 213424 KB Output is correct
37 Correct 95 ms 213324 KB Output is correct
38 Correct 93 ms 213324 KB Output is correct
39 Correct 93 ms 213316 KB Output is correct
40 Correct 92 ms 213324 KB Output is correct
41 Correct 93 ms 213400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 213400 KB Output is correct
2 Correct 89 ms 213356 KB Output is correct
3 Correct 88 ms 213388 KB Output is correct
4 Correct 88 ms 213328 KB Output is correct
5 Correct 89 ms 213384 KB Output is correct
6 Correct 87 ms 213324 KB Output is correct
7 Correct 89 ms 213372 KB Output is correct
8 Correct 90 ms 213376 KB Output is correct
9 Correct 90 ms 213368 KB Output is correct
10 Correct 88 ms 213348 KB Output is correct
11 Correct 89 ms 213420 KB Output is correct
12 Correct 88 ms 213368 KB Output is correct
13 Correct 89 ms 213348 KB Output is correct
14 Correct 91 ms 213356 KB Output is correct
15 Correct 88 ms 213300 KB Output is correct
16 Correct 90 ms 213424 KB Output is correct
17 Correct 92 ms 213324 KB Output is correct
18 Correct 89 ms 213348 KB Output is correct
19 Correct 89 ms 213368 KB Output is correct
20 Correct 88 ms 213392 KB Output is correct
21 Correct 90 ms 213336 KB Output is correct
22 Correct 92 ms 213400 KB Output is correct
23 Correct 90 ms 213304 KB Output is correct
24 Correct 89 ms 213388 KB Output is correct
25 Correct 96 ms 213328 KB Output is correct
26 Correct 94 ms 213312 KB Output is correct
27 Correct 94 ms 213384 KB Output is correct
28 Correct 96 ms 213412 KB Output is correct
29 Correct 111 ms 213416 KB Output is correct
30 Correct 98 ms 213412 KB Output is correct
31 Correct 113 ms 213360 KB Output is correct
32 Correct 93 ms 213384 KB Output is correct
33 Correct 94 ms 213308 KB Output is correct
34 Correct 93 ms 213320 KB Output is correct
35 Correct 93 ms 213420 KB Output is correct
36 Correct 94 ms 213424 KB Output is correct
37 Correct 95 ms 213324 KB Output is correct
38 Correct 93 ms 213324 KB Output is correct
39 Correct 93 ms 213316 KB Output is correct
40 Correct 92 ms 213324 KB Output is correct
41 Correct 93 ms 213400 KB Output is correct
42 Correct 89 ms 213392 KB Output is correct
43 Correct 94 ms 213304 KB Output is correct
44 Correct 90 ms 213340 KB Output is correct
45 Correct 93 ms 213376 KB Output is correct
46 Correct 94 ms 213404 KB Output is correct
47 Correct 98 ms 213396 KB Output is correct
48 Correct 95 ms 213328 KB Output is correct
49 Correct 96 ms 213420 KB Output is correct
50 Correct 112 ms 213420 KB Output is correct
51 Correct 124 ms 213308 KB Output is correct
52 Correct 105 ms 213424 KB Output is correct
53 Correct 213 ms 213420 KB Output is correct
54 Correct 197 ms 213432 KB Output is correct
55 Correct 219 ms 213420 KB Output is correct
56 Correct 93 ms 213348 KB Output is correct
57 Correct 96 ms 213344 KB Output is correct
58 Correct 99 ms 213360 KB Output is correct
59 Correct 97 ms 213368 KB Output is correct
60 Correct 128 ms 213352 KB Output is correct
61 Correct 98 ms 213332 KB Output is correct
62 Correct 103 ms 213312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 213400 KB Output is correct
2 Correct 89 ms 213356 KB Output is correct
3 Correct 88 ms 213388 KB Output is correct
4 Correct 88 ms 213328 KB Output is correct
5 Correct 89 ms 213384 KB Output is correct
6 Correct 87 ms 213324 KB Output is correct
7 Correct 89 ms 213372 KB Output is correct
8 Correct 90 ms 213376 KB Output is correct
9 Correct 90 ms 213368 KB Output is correct
10 Correct 88 ms 213348 KB Output is correct
11 Correct 89 ms 213420 KB Output is correct
12 Correct 88 ms 213368 KB Output is correct
13 Correct 89 ms 213348 KB Output is correct
14 Correct 91 ms 213356 KB Output is correct
15 Correct 88 ms 213300 KB Output is correct
16 Correct 90 ms 213424 KB Output is correct
17 Correct 92 ms 213324 KB Output is correct
18 Correct 89 ms 213348 KB Output is correct
19 Correct 89 ms 213368 KB Output is correct
20 Correct 88 ms 213392 KB Output is correct
21 Correct 90 ms 213336 KB Output is correct
22 Correct 92 ms 213400 KB Output is correct
23 Correct 90 ms 213304 KB Output is correct
24 Correct 89 ms 213388 KB Output is correct
25 Correct 96 ms 213328 KB Output is correct
26 Correct 94 ms 213312 KB Output is correct
27 Correct 94 ms 213384 KB Output is correct
28 Correct 96 ms 213412 KB Output is correct
29 Correct 111 ms 213416 KB Output is correct
30 Correct 98 ms 213412 KB Output is correct
31 Correct 113 ms 213360 KB Output is correct
32 Correct 93 ms 213384 KB Output is correct
33 Correct 94 ms 213308 KB Output is correct
34 Correct 93 ms 213320 KB Output is correct
35 Correct 93 ms 213420 KB Output is correct
36 Correct 94 ms 213424 KB Output is correct
37 Correct 95 ms 213324 KB Output is correct
38 Correct 93 ms 213324 KB Output is correct
39 Correct 93 ms 213316 KB Output is correct
40 Correct 92 ms 213324 KB Output is correct
41 Correct 93 ms 213400 KB Output is correct
42 Correct 89 ms 213392 KB Output is correct
43 Correct 94 ms 213304 KB Output is correct
44 Correct 90 ms 213340 KB Output is correct
45 Correct 93 ms 213376 KB Output is correct
46 Correct 94 ms 213404 KB Output is correct
47 Correct 98 ms 213396 KB Output is correct
48 Correct 95 ms 213328 KB Output is correct
49 Correct 96 ms 213420 KB Output is correct
50 Correct 112 ms 213420 KB Output is correct
51 Correct 124 ms 213308 KB Output is correct
52 Correct 105 ms 213424 KB Output is correct
53 Correct 213 ms 213420 KB Output is correct
54 Correct 197 ms 213432 KB Output is correct
55 Correct 219 ms 213420 KB Output is correct
56 Correct 93 ms 213348 KB Output is correct
57 Correct 96 ms 213344 KB Output is correct
58 Correct 99 ms 213360 KB Output is correct
59 Correct 97 ms 213368 KB Output is correct
60 Correct 128 ms 213352 KB Output is correct
61 Correct 98 ms 213332 KB Output is correct
62 Correct 103 ms 213312 KB Output is correct
63 Runtime error 274 ms 432584 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 213400 KB Output is correct
2 Correct 89 ms 213356 KB Output is correct
3 Correct 88 ms 213388 KB Output is correct
4 Correct 88 ms 213328 KB Output is correct
5 Correct 89 ms 213384 KB Output is correct
6 Correct 87 ms 213324 KB Output is correct
7 Correct 89 ms 213372 KB Output is correct
8 Correct 90 ms 213376 KB Output is correct
9 Correct 90 ms 213368 KB Output is correct
10 Correct 88 ms 213348 KB Output is correct
11 Correct 89 ms 213420 KB Output is correct
12 Correct 88 ms 213368 KB Output is correct
13 Correct 89 ms 213348 KB Output is correct
14 Correct 91 ms 213356 KB Output is correct
15 Correct 88 ms 213300 KB Output is correct
16 Correct 90 ms 213424 KB Output is correct
17 Correct 92 ms 213324 KB Output is correct
18 Correct 89 ms 213348 KB Output is correct
19 Correct 89 ms 213368 KB Output is correct
20 Correct 88 ms 213392 KB Output is correct
21 Correct 90 ms 213336 KB Output is correct
22 Correct 92 ms 213400 KB Output is correct
23 Correct 90 ms 213304 KB Output is correct
24 Correct 89 ms 213388 KB Output is correct
25 Correct 96 ms 213328 KB Output is correct
26 Correct 94 ms 213312 KB Output is correct
27 Correct 94 ms 213384 KB Output is correct
28 Correct 96 ms 213412 KB Output is correct
29 Correct 111 ms 213416 KB Output is correct
30 Correct 98 ms 213412 KB Output is correct
31 Correct 113 ms 213360 KB Output is correct
32 Correct 93 ms 213384 KB Output is correct
33 Correct 94 ms 213308 KB Output is correct
34 Correct 93 ms 213320 KB Output is correct
35 Correct 93 ms 213420 KB Output is correct
36 Correct 94 ms 213424 KB Output is correct
37 Correct 95 ms 213324 KB Output is correct
38 Correct 93 ms 213324 KB Output is correct
39 Correct 93 ms 213316 KB Output is correct
40 Correct 92 ms 213324 KB Output is correct
41 Correct 93 ms 213400 KB Output is correct
42 Correct 89 ms 213392 KB Output is correct
43 Correct 94 ms 213304 KB Output is correct
44 Correct 90 ms 213340 KB Output is correct
45 Correct 93 ms 213376 KB Output is correct
46 Correct 94 ms 213404 KB Output is correct
47 Correct 98 ms 213396 KB Output is correct
48 Correct 95 ms 213328 KB Output is correct
49 Correct 96 ms 213420 KB Output is correct
50 Correct 112 ms 213420 KB Output is correct
51 Correct 124 ms 213308 KB Output is correct
52 Correct 105 ms 213424 KB Output is correct
53 Correct 213 ms 213420 KB Output is correct
54 Correct 197 ms 213432 KB Output is correct
55 Correct 219 ms 213420 KB Output is correct
56 Correct 93 ms 213348 KB Output is correct
57 Correct 96 ms 213344 KB Output is correct
58 Correct 99 ms 213360 KB Output is correct
59 Correct 97 ms 213368 KB Output is correct
60 Correct 128 ms 213352 KB Output is correct
61 Correct 98 ms 213332 KB Output is correct
62 Correct 103 ms 213312 KB Output is correct
63 Runtime error 274 ms 432584 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -