Submission #199929

# Submission time Handle Problem Language Result Execution time Memory
199929 2020-02-04T06:20:42 Z SamAnd Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
375 ms 25828 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;

int n, m;
int a[N];

int z;
vector<long long> v;
map<long long, int> mp;

int t[N * 4];
void ubd(int tl, int tr, int x, int y, int pos)
{
    if (tl == tr)
    {
        t[pos] = min(t[pos], y);
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, y, pos * 2);
    else
        ubd(m + 1, tr, x, y, pos * 2 + 1);
    t[pos] = min(t[pos * 2], t[pos * 2 + 1]);
}
int qry(int tl, int tr, int l, int r, int pos)
{
    if (l > r)
        return N;
    if (tl == l && tr == r)
        return t[pos];
    int m = (tl + tr) / 2;
    return min(qry(tl, m, l, min(m, r), pos * 2),
               qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

int dp[N];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 0; i <= n; ++i)
    {
        v.push_back(a[i] - i * 1LL * m);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i)
    {
        if (!i || v[i] != v[i - 1])
            mp[v[i]] = ++z;
    }
    for (int i = 0; i <= n; ++i)
    {
        a[i] = mp[a[i] - i * 1LL * m];
    }
    for (int i = 0; i < N * 4; ++i)
        t[i] = N;
    ubd(1, z, a[0], dp[0], 1);
    for (int i = 1; i <= n; ++i)
    {
        dp[i] = qry(1, z, a[i], z, 1) + i - 1;
        ubd(1, z, a[i], dp[i] - i, 1);
    }
    int ans = n;
    for (int i = 1; i <= n; ++i)
        ans = min(ans, dp[i] + (n - i));
    printf("%d\n", ans);
    return 0;
}

Compilation message

triusis.cpp: In function 'int main()':
triusis.cpp:49:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
triusis.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
triusis.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8184 KB Output is correct
2 Correct 9 ms 8312 KB Output is correct
3 Correct 9 ms 8184 KB Output is correct
4 Correct 9 ms 8184 KB Output is correct
5 Correct 7 ms 8184 KB Output is correct
6 Correct 9 ms 8184 KB Output is correct
7 Correct 9 ms 8184 KB Output is correct
8 Correct 9 ms 8184 KB Output is correct
9 Correct 9 ms 8184 KB Output is correct
10 Correct 10 ms 8184 KB Output is correct
11 Correct 9 ms 8184 KB Output is correct
12 Correct 9 ms 8184 KB Output is correct
13 Correct 9 ms 8184 KB Output is correct
14 Correct 9 ms 8184 KB Output is correct
15 Correct 9 ms 8184 KB Output is correct
16 Correct 9 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8184 KB Output is correct
2 Correct 9 ms 8184 KB Output is correct
3 Correct 10 ms 8184 KB Output is correct
4 Correct 12 ms 8440 KB Output is correct
5 Correct 12 ms 8568 KB Output is correct
6 Correct 12 ms 8440 KB Output is correct
7 Correct 13 ms 8568 KB Output is correct
8 Correct 12 ms 8568 KB Output is correct
9 Correct 12 ms 8568 KB Output is correct
10 Correct 12 ms 8568 KB Output is correct
11 Correct 13 ms 8312 KB Output is correct
12 Correct 10 ms 8312 KB Output is correct
13 Correct 12 ms 8568 KB Output is correct
14 Correct 14 ms 8568 KB Output is correct
15 Correct 11 ms 8440 KB Output is correct
16 Correct 12 ms 8568 KB Output is correct
17 Correct 13 ms 8568 KB Output is correct
18 Correct 9 ms 8184 KB Output is correct
19 Correct 9 ms 8312 KB Output is correct
20 Correct 9 ms 8184 KB Output is correct
21 Correct 9 ms 8184 KB Output is correct
22 Correct 7 ms 8184 KB Output is correct
23 Correct 9 ms 8184 KB Output is correct
24 Correct 9 ms 8184 KB Output is correct
25 Correct 9 ms 8184 KB Output is correct
26 Correct 9 ms 8184 KB Output is correct
27 Correct 10 ms 8184 KB Output is correct
28 Correct 9 ms 8184 KB Output is correct
29 Correct 9 ms 8184 KB Output is correct
30 Correct 9 ms 8184 KB Output is correct
31 Correct 9 ms 8184 KB Output is correct
32 Correct 9 ms 8184 KB Output is correct
33 Correct 9 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8568 KB Output is correct
2 Correct 14 ms 8568 KB Output is correct
3 Correct 14 ms 8568 KB Output is correct
4 Correct 13 ms 8568 KB Output is correct
5 Correct 11 ms 8316 KB Output is correct
6 Correct 10 ms 8316 KB Output is correct
7 Correct 11 ms 8440 KB Output is correct
8 Correct 10 ms 8312 KB Output is correct
9 Correct 12 ms 8568 KB Output is correct
10 Correct 12 ms 8568 KB Output is correct
11 Correct 9 ms 8184 KB Output is correct
12 Correct 9 ms 8184 KB Output is correct
13 Correct 10 ms 8184 KB Output is correct
14 Correct 12 ms 8440 KB Output is correct
15 Correct 12 ms 8568 KB Output is correct
16 Correct 12 ms 8440 KB Output is correct
17 Correct 13 ms 8568 KB Output is correct
18 Correct 12 ms 8568 KB Output is correct
19 Correct 12 ms 8568 KB Output is correct
20 Correct 12 ms 8568 KB Output is correct
21 Correct 13 ms 8312 KB Output is correct
22 Correct 10 ms 8312 KB Output is correct
23 Correct 12 ms 8568 KB Output is correct
24 Correct 14 ms 8568 KB Output is correct
25 Correct 11 ms 8440 KB Output is correct
26 Correct 12 ms 8568 KB Output is correct
27 Correct 13 ms 8568 KB Output is correct
28 Correct 9 ms 8184 KB Output is correct
29 Correct 9 ms 8312 KB Output is correct
30 Correct 9 ms 8184 KB Output is correct
31 Correct 9 ms 8184 KB Output is correct
32 Correct 7 ms 8184 KB Output is correct
33 Correct 9 ms 8184 KB Output is correct
34 Correct 9 ms 8184 KB Output is correct
35 Correct 9 ms 8184 KB Output is correct
36 Correct 9 ms 8184 KB Output is correct
37 Correct 10 ms 8184 KB Output is correct
38 Correct 9 ms 8184 KB Output is correct
39 Correct 9 ms 8184 KB Output is correct
40 Correct 9 ms 8184 KB Output is correct
41 Correct 9 ms 8184 KB Output is correct
42 Correct 9 ms 8184 KB Output is correct
43 Correct 9 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8568 KB Output is correct
2 Correct 14 ms 8568 KB Output is correct
3 Correct 14 ms 8568 KB Output is correct
4 Correct 13 ms 8568 KB Output is correct
5 Correct 11 ms 8316 KB Output is correct
6 Correct 10 ms 8316 KB Output is correct
7 Correct 11 ms 8440 KB Output is correct
8 Correct 10 ms 8312 KB Output is correct
9 Correct 12 ms 8568 KB Output is correct
10 Correct 12 ms 8568 KB Output is correct
11 Correct 9 ms 8184 KB Output is correct
12 Correct 9 ms 8184 KB Output is correct
13 Correct 10 ms 8184 KB Output is correct
14 Correct 12 ms 8440 KB Output is correct
15 Correct 12 ms 8568 KB Output is correct
16 Correct 12 ms 8440 KB Output is correct
17 Correct 13 ms 8568 KB Output is correct
18 Correct 12 ms 8568 KB Output is correct
19 Correct 12 ms 8568 KB Output is correct
20 Correct 12 ms 8568 KB Output is correct
21 Correct 13 ms 8312 KB Output is correct
22 Correct 10 ms 8312 KB Output is correct
23 Correct 12 ms 8568 KB Output is correct
24 Correct 14 ms 8568 KB Output is correct
25 Correct 11 ms 8440 KB Output is correct
26 Correct 12 ms 8568 KB Output is correct
27 Correct 13 ms 8568 KB Output is correct
28 Correct 177 ms 23800 KB Output is correct
29 Correct 375 ms 25828 KB Output is correct
30 Correct 319 ms 25828 KB Output is correct
31 Correct 325 ms 25700 KB Output is correct
32 Correct 165 ms 24548 KB Output is correct
33 Correct 163 ms 24932 KB Output is correct
34 Correct 59 ms 13412 KB Output is correct
35 Correct 54 ms 13412 KB Output is correct
36 Correct 130 ms 18404 KB Output is correct
37 Correct 48 ms 12652 KB Output is correct
38 Correct 162 ms 24804 KB Output is correct
39 Correct 171 ms 24676 KB Output is correct
40 Correct 9 ms 8184 KB Output is correct
41 Correct 9 ms 8312 KB Output is correct
42 Correct 9 ms 8184 KB Output is correct
43 Correct 9 ms 8184 KB Output is correct
44 Correct 7 ms 8184 KB Output is correct
45 Correct 9 ms 8184 KB Output is correct
46 Correct 9 ms 8184 KB Output is correct
47 Correct 9 ms 8184 KB Output is correct
48 Correct 9 ms 8184 KB Output is correct
49 Correct 10 ms 8184 KB Output is correct
50 Correct 9 ms 8184 KB Output is correct
51 Correct 9 ms 8184 KB Output is correct
52 Correct 9 ms 8184 KB Output is correct
53 Correct 9 ms 8184 KB Output is correct
54 Correct 9 ms 8184 KB Output is correct
55 Correct 9 ms 8184 KB Output is correct