답안 #211628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211628 2020-03-20T21:02:30 Z DS007 Bali Sculptures (APIO15_sculpture) C++14
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2005;
int n, a, b;
int y[N], p[N];
int dp[N][N];

void compute(int i, int l, int r, int optl, int optr) {
    if (l > r)
        return;

    int mid = (l + r) / 2;
    pair<int, int> best = {1e18, -1};

    for (int j = optl; j <= min (optr, mid - 1); j++)
        best = min(best, {dp[i - 1][j] | (p[mid] - p[j + 1] + y[j + 1]), j});

    dp[i][mid] = best.first;
    compute(i, l, mid - 1, optl, best.second);
    compute(i, mid + 1, r, best.second, optr);
}

void solveTestCase() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> y[i];

    p[0] = y[0];
    for (int i = 1; i < n; i++)
        p[i] = p[i - 1] + y[i];

    for (int i = 0; i < n; i++)
        dp[1][i] = p[i];

    for (int i = 2; i <= n; i++)
        compute(i, 0, n - 1, 0, n - 1);

    int ans = 1e18;
    for (int i = a; i <= b; i++)
        ans = min(ans, dp[i][n - 1]);
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    //cin >> test;
    while (test--)
        solveTestCase();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -