답안 #226344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226344 2020-04-23T12:19:05 Z emil_physmath K개의 묶음 (IZhO14_blocks) C++17
0 / 100
12 ms 2048 KB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int dp[101][100'000];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    dp[1][0] = a[0];
    for (int i = 1; i < n; ++i)
        dp[1][i] = max(dp[1][i - 1], a[i]);
    for (int j = 2; j <= k; ++j)
        dp[j][0] = 1000'000 * k + 1;
    vector<int> st;
    vector<vector<int>> dpst(k + 1);
    dpst[1].push_back(0);
    for (int i = 1; i < n; ++i)
    {
        auto it = upper_bound(st.rbegin(), st.rend(), i, [&a](int i, int j){ return a[i] < a[j]; });
        int m = (it == st.rend() ? -1 : *it);
        for (int j = 1; j <= k; ++j)
        {
            if (j > 1)
            {
                int cur = 1000'000 * k + 1;
                if (m != -1)
                    cur = min(cur, dp[j][m]);
                else
                    m = 0;
                auto it = lower_bound(dpst[j - 1].begin(), dpst[j - 1].end(), m);
                if (it != dpst[j - 1].end())
                    cur = min(cur, dp[j - 1][*it] + a[i]);
                dp[j][i] = cur;
            }
            while (dpst[j].size() && dp[j][dpst[j].back()] >= dp[j][i])
                dpst[j].pop_back();
            dpst[j].push_back(i);
        }
        while (st.size() && a[st.back()] <= a[i])
            st.pop_back();
        st.push_back(i);
    }
    cout << dp[k][n - 1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Incorrect 5 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 404 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Incorrect 5 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -