답안 #577164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577164 2022-06-14T08:16:17 Z tengiz05 Tortoise (CEOI21_tortoise) C++17
0 / 100
1 ms 352 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void chmax(i64 &a, i64 b) {
    if (a < b)
        a = b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<int> a(n + 1), b, c;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] == -1) {
            c.push_back(i);
        }
    }
    
    vector<int> l(n + 1), r(n + 1);
    int lst = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == -1)
            lst = i;
        l[i] = lst;
    }
    lst = n + 1;
    for (int i = n; i >= 1; i--) {
        if (a[i] == -1)
            lst = i;
        r[i] = lst;
    }
    
    for (int i = 1; i <= n; i++) {
        if (a[i] > 0) {
            int x = n;
            if (l[i] != 0) {
                x = i - l[i];
            }
            if (r[i] != n + 1) {
                x = min(x, r[i] - i);
            }
            for (int j = 1; j <= min(a[i], (i + x) / (2 * x)); j++) {
                b.push_back(i);
            }
        }
    }
    
    vector dp(2 * n + 1, vector(n + 1, vector<i64>(n + 1, -1)));
    
    dp[0][1][0] = 0;
    
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 0; k < int(b.size()); k++) {
                if (dp[i][j][k] == -1)
                    continue;
                chmax(dp[i][j][k + 1], dp[i][j][k]);
                int x = b[k];
                if (l[x] != 0) {
                    int y = l[x];
                    if (2 + i + abs(x - j) <= 2 * x) {
                        chmax(dp[min(2 * n, i + abs(x - j) + 2 * abs(x - y))][x][k + 1], dp[i][j][k] + 1);
                    }
                }
                if (r[x] != n + 1) {
                    int y = r[x];
                    if (2 + i + abs(x - j) <= 2 * x) {
                        chmax(dp[min(2 * n, i + abs(x - j) + abs(x - y))][y][k + 1], dp[i][j][k] + 1);
                    }
                }
            }
        }
    }
    
    i64 ans = 0;
    for (int i = 0; i <= 2 * n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 0; k <= int(b.size()); k++) {
                ans = max(ans, dp[i][j][k]);
            }
        }
    }
    i64 sum = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > 0) {
            sum += a[i];
        }
    }
    
    cout << sum - ans << "\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 320 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 320 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 320 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 320 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 320 KB Output isn't correct
19 Halted 0 ms 0 KB -