Submission #577112

# Submission time Handle Problem Language Result Execution time Memory
577112 2022-06-14T06:06:43 Z tengiz05 Tortoise (CEOI21_tortoise) C++17
0 / 100
0 ms 340 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void chmax(int &a, int 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] > 0) {
            b.push_back(i);
        } else if (a[i] == -1) {
            c.push_back(i);
        }
    }
    
    vector dp(2 * n + 1, vector(n + 1, vector<int>(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;
                for (int p = k; p < int(b.size()); p++) {
                    int x = b[k];
                    for (int y : c) {
                        if ((i + abs(x - j) + 1) / 2 <= x) {
                            chmax(dp[min(2 * n, i + abs(x - j) + abs(x - y))][y][p + 1], dp[i][j][k] + 1);
                        }
                    }
                }
            }
        }
    }
    
    int 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]);
            }
        }
    }
    
    cout << b.size() - ans << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -