답안 #713382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713382 2023-03-21T20:14:21 Z mtxas Rabbit Carrot (LMIO19_triusis) C++14
35 / 100
150 ms 98812 KB
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    const int inf = 0x3f3f3f3f;
    int n, m;
    cin >> n >> m;
    if(n > 5000)
    {
        assert(false);
    }
    vector<int> a(n + 1);
    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    /// calculate c
    set<int> s;
//    for(int i = 1; i <= n; ++i)
//    {
//        s.insert(a[i]);
//        s.insert(a[i] + 1);
//        s.insert(max(0, a[i] - 1));
//        s.insert(a[i] + m);
//        s.insert(a[i] + m + 1);
//        s.insert(max(0, a[i] + m - 1 ));
//        s.insert(max(0, a[i] - m));
//        s.insert(max(0, a[i] - m + 1));
//        s.insert(max(0, a[i] - m - 1));
//    }
    for(int i=1; i<=5000; ++i)
    {
        s.insert(i);
    }
    s.insert(0);
    s.insert(inf);
    vector<int> c {-1};
    for(auto x : s)
    {
        c.push_back(x);
    }
    int k = c.size() - 1;
    /// calc L
    vector<int> L(k + 1);
    for(int i = 1; i <= k; ++i)
    {
        for(L[i] = i; L[i] >= 1; --L[i])
        {
            if(c[i] - c[L[i]] > m) break;
        }
        L[i]++;
    }
    /// calc dp
    vector<vector<int>> dp(n + 1, vector<int> (k + 1, inf));
    assert(c[1] == 0 && (c[2] != 0));
    dp[0][1] = 0;
    vector<int> curSuff(k + 2, inf), prvSuff(k + 2, inf);
    prvSuff[1] = 0;
    for(int i = 1; i <= n; ++i)
    {
        curSuff.assign(k + 2, inf);
        for(int j = k; j >= 1; --j)
        {
            dp[i][j] = (a[i] != c[j]) + prvSuff[L[j]];
            curSuff[j] = min(curSuff[j + 1], dp[i][j]);
        }
        prvSuff = curSuff;
    }
    /// print ans
    int ans = inf;
    for(int j = 1; j <= k ; ++j)
    {
        ans = min(ans, dp[n][j]);
    }
    cout << ans << '\n';
}
signed main()
{
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 12 ms 720 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 12 ms 720 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 112 ms 80084 KB Output is correct
21 Correct 147 ms 98712 KB Output is correct
22 Correct 141 ms 98668 KB Output is correct
23 Correct 146 ms 98760 KB Output is correct
24 Correct 150 ms 98812 KB Output is correct
25 Correct 150 ms 98788 KB Output is correct
26 Correct 135 ms 98764 KB Output is correct
27 Correct 136 ms 98764 KB Output is correct
28 Correct 134 ms 98760 KB Output is correct
29 Correct 143 ms 98636 KB Output is correct
30 Correct 135 ms 98744 KB Output is correct
31 Correct 135 ms 98636 KB Output is correct
32 Correct 142 ms 98788 KB Output is correct
33 Correct 147 ms 98764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 112 ms 80084 KB Output is correct
5 Correct 147 ms 98712 KB Output is correct
6 Correct 141 ms 98668 KB Output is correct
7 Correct 146 ms 98760 KB Output is correct
8 Correct 150 ms 98812 KB Output is correct
9 Correct 150 ms 98788 KB Output is correct
10 Correct 135 ms 98764 KB Output is correct
11 Correct 136 ms 98764 KB Output is correct
12 Correct 134 ms 98760 KB Output is correct
13 Correct 143 ms 98636 KB Output is correct
14 Correct 135 ms 98744 KB Output is correct
15 Correct 135 ms 98636 KB Output is correct
16 Correct 142 ms 98788 KB Output is correct
17 Correct 147 ms 98764 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 12 ms 720 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 139 ms 98764 KB Output is correct
35 Incorrect 146 ms 98712 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 98764 KB Output is correct
2 Incorrect 146 ms 98712 KB Output isn't correct
3 Halted 0 ms 0 KB -