Submission #470334

# Submission time Handle Problem Language Result Execution time Memory
470334 2021-09-03T14:00:39 Z prvocislo Global Warming (CEOI18_glo) C++17
100 / 100
364 ms 10588 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
typedef long long ll;
using namespace std;

int n, x;
map<int, int> dp[2]; // dp[pridali sme uz x?][koniec] = dlzka
void update(int l, int len, int end)
{
    if (!dp[l].count(end)) dp[l][end] = len;
    else dp[l][end] = max(dp[l][end], len);
    auto it = dp[l].find(end);
    if (it != dp[l].begin() && prev(it)->second >= len) 
    {
        dp[l].erase(it);
        return;
    }
    while (next(it) != dp[l].end() && next(it)->second <= len)
    {
        dp[l].erase(next(it));
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    vector<int> t(n);
    for (int i = 0; i < n; i++) cin >> t[i];
    dp[0][0] = dp[1][0] = 0;
    for (int i = 0; i < n; i++)
    {
        // pouzijeme moznost zvysit sufix
        int len = prev(dp[0].lower_bound(t[i] + x))->second + 1;
        update(1, len, t[i]);
        for (int j = 0; j < 2; j++)
        {
            auto it = prev(dp[j].lower_bound(t[i]));
            update(j, it->second + 1, t[i]);
        }
        //cout << i << ", " << t[i] << ": "
        //     << prev(dp[0].end())->second << " " << prev(dp[1].end())->second << endl;
    }
    cout << prev(dp[1].end())->second << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 1240 KB Output is correct
2 Correct 243 ms 1476 KB Output is correct
3 Correct 243 ms 1208 KB Output is correct
4 Correct 243 ms 1220 KB Output is correct
5 Correct 280 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 540 KB Output is correct
2 Correct 55 ms 632 KB Output is correct
3 Correct 56 ms 636 KB Output is correct
4 Correct 51 ms 2900 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 73 ms 2756 KB Output is correct
7 Correct 42 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 716 KB Output is correct
2 Correct 111 ms 856 KB Output is correct
3 Correct 222 ms 1256 KB Output is correct
4 Correct 130 ms 5696 KB Output is correct
5 Correct 161 ms 5300 KB Output is correct
6 Correct 233 ms 9924 KB Output is correct
7 Correct 222 ms 9912 KB Output is correct
8 Correct 83 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 254 ms 1240 KB Output is correct
28 Correct 243 ms 1476 KB Output is correct
29 Correct 243 ms 1208 KB Output is correct
30 Correct 243 ms 1220 KB Output is correct
31 Correct 280 ms 10588 KB Output is correct
32 Correct 55 ms 540 KB Output is correct
33 Correct 55 ms 632 KB Output is correct
34 Correct 56 ms 636 KB Output is correct
35 Correct 51 ms 2900 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 73 ms 2756 KB Output is correct
38 Correct 42 ms 536 KB Output is correct
39 Correct 111 ms 716 KB Output is correct
40 Correct 111 ms 856 KB Output is correct
41 Correct 222 ms 1256 KB Output is correct
42 Correct 130 ms 5696 KB Output is correct
43 Correct 161 ms 5300 KB Output is correct
44 Correct 233 ms 9924 KB Output is correct
45 Correct 222 ms 9912 KB Output is correct
46 Correct 83 ms 716 KB Output is correct
47 Correct 117 ms 724 KB Output is correct
48 Correct 114 ms 736 KB Output is correct
49 Correct 239 ms 1172 KB Output is correct
50 Correct 254 ms 10376 KB Output is correct
51 Correct 245 ms 10180 KB Output is correct
52 Correct 364 ms 10540 KB Output is correct
53 Correct 254 ms 10364 KB Output is correct
54 Correct 214 ms 10564 KB Output is correct
55 Correct 179 ms 1220 KB Output is correct