답안 #991177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991177 2024-06-01T13:54:58 Z yoav_s Tortoise (CEOI21_tortoise) C++17
8 / 100
355 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;

typedef int ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef vector<vvv> vvvv;
typedef pair<ll, ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define setmax(a, b) a = max(a, b)

const ll INF = 1e18;
const ll mod = 1e9 + 7;


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll N;
    cin >> N;
    v a(N);
    for (ll i = 0; i < N; i++) cin >> a[i];
    v firstParkLeft(N, -1), firstParkRight(N, N);
    ll lastPark = -1;
    for (ll i = 0; i < N; i++)
    {
        if (a[i] == -1) lastPark = i;
        firstParkLeft[i] = lastPark;
    }
    lastPark = N;
    for (ll i = N - 1; i >= 0; i--)
    {
        if (a[i] == -1) lastPark = i;
        firstParkRight[i] = lastPark;
    }
    vvvv dp(2 * N + 1, vvv(N, vv(N + 1, v(2, 0))));
    for (ll firstPos = 2 * N - 1; firstPos >= 0; firstPos--)
    {
        for (ll secondPos = 0; secondPos < N; secondPos++)
        {
            for (ll lastEaten = N - 1; lastEaten >= 0; lastEaten--)
            {
                //state = 0, looking for somewhere to eat
                dp[firstPos][secondPos][lastEaten][0] = dp[firstPos][secondPos][lastEaten + 1][0];
                if (a[lastEaten] >= 1)
                {
                    ll distance = abs(secondPos - lastEaten);
                    if ((firstPos + distance) / 2 <= lastEaten)
                    {
                        setmax(dp[firstPos][secondPos][lastEaten][0], dp[firstPos + distance][lastEaten][lastEaten + 1][1] + 1);
                    }
                }
                if (firstParkLeft[secondPos] > -1)
                {
                    ll distance = abs(secondPos - firstParkLeft[secondPos]);
                    if (firstPos + distance < 2 * N)
                        setmax(dp[firstPos][secondPos][lastEaten][1], dp[firstPos + distance][firstParkLeft[secondPos]][lastEaten][0]);
                }
                if (firstParkRight[secondPos] < N)
                {
                    ll distance = abs(secondPos - firstParkRight[secondPos]);
                    if (firstPos + distance < 2 * N)
                        setmax(dp[firstPos][secondPos][lastEaten][1], dp[firstPos + distance][firstParkRight[secondPos]][lastEaten][0]);
                }
            }
        }
    }
    ll sum = 0;
    for (auto x : a) if (x > 0) sum += x;
    cout << sum - dp[0][0][0][0] << "\n";
    return 0;
}

Compilation message

tortoise.cpp:29:16: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
   29 | const ll INF = 1e18;
      |                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 964 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 968 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 964 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 968 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Runtime error 355 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 964 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 968 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Runtime error 355 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 964 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 968 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Runtime error 355 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 964 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 968 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Runtime error 355 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -