Submission #742386

# Submission time Handle Problem Language Result Execution time Memory
742386 2023-05-16T08:04:57 Z maomao90 Tortoise (CEOI21_tortoise) C++17
0 / 100
1 ms 340 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 5005;

int n;
int a[MAXN];
int lft[MAXN], rht[MAXN];
int dp[MAXN][MAXN * 4];
int ans;

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n;
    ll sm = 0;
    REP (i, 0, n) {
        cin >> a[i];
        sm += max(0, a[i]);
    }
    REP (i, 0, n) {
        if (a[i] == -1) {
            lft[i] = i;
        } else {
            lft[i] = i == 0 ? -INF : lft[i - 1];
        }
    }
    rht[n] = INF;
    RREP (i, n - 1, 0) {
        if (a[i] == -1) {
            rht[i] = i;
        } else {
            rht[i] = rht[i + 1];
        }
    }
    REP (i, 0, n) {
        REP (j, 0, i * 2 + 1) {
            if (a[i] <= 0) {
                mxto(dp[i + 1][j], dp[i][j]);
                continue;
            }
            REP (k, 1, a[i] + 1) {
                int near = min(i - lft[i], rht[i] - i);
                ll nj = j + (ll) near * 2 * (k - 1);
                if (nj > i * 2) {
                    break;
                }
                mxto(ans, dp[i][j] + k);
                if (lft[i] != -INF) {
                    mxto(dp[i + 1][nj + i - lft[i] + i + 1 - lft[i]],
                            dp[i][j] + k);
                }
                if (rht[i] != INF) {
                    RREP (l, rht[i], i + 1) {
                        mxto(dp[l][nj + rht[i] - i + rht[i] - l], dp[i][j] + k);
                    }
                }
            }
        }
    }
    cout << sm - ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -