Submission #749264

# Submission time Handle Problem Language Result Execution time Memory
749264 2023-05-27T15:30:47 Z Desh03 Collecting Stamps 3 (JOI20_ho_t3) C++17
15 / 100
118 ms 1876 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

map<int, int> mp;
set<int> x;
multiset<int> y;
int l;
vector<vector<vector<pair<int, int>>>> dp;

int recurse(int cur, int t, bool s, int ll, int rr) {
    if (x.empty() || *--y.end() < t) return 0;
    if (dp[s][ll][rr].first < t) return dp[s][ll][rr].second;
    auto it = x.upper_bound(cur);
    int k = 0;
    if (it == x.end()) k = 1, it = x.begin();
    int p = *it;
    int cost = (k ? l - cur + p : p - cur);
    x.erase(p);
    y.erase(y.find(mp[p]));
    int g = (t + cost <= mp[p]) + recurse(p, t + cost, 1, ll, rr + 1);
    x.insert(p);
    y.insert(mp[p]);
    it = x.upper_bound(cur);
    k = 0;
    if (it == x.begin()) k = 1, it = --x.end();
    else --it;
    p = *it;
    x.erase(p);
    y.erase(y.find(mp[p]));
    cost = (k ? cur + l - p : cur - p);
    g = max(g, (t + cost <= mp[p]) + recurse(p, t + cost, 0, ll + 1, rr));
    x.insert(p);
    y.insert(mp[p]);
    if (g == dp[s][ll][rr].second) dp[s][ll][rr] = min(dp[s][ll][rr], {t, g});
    else if (g > dp[s][ll][rr].second) dp[s][ll][rr] = {t, g};
    return dp[s][ll][rr].second;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n >> l;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        x.insert(k);
    }
    dp = vector<vector<vector<pair<int, int>>>> (2, vector<vector<pair<int, int>>> (n, vector<pair<int, int>> (n, {1e18, 0})));
    for (auto k : x) cin >> mp[k], y.insert(mp[k]);
    cout << recurse(0, 0, 0, 0, 0) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 118 ms 1876 KB Output is correct
19 Correct 89 ms 1236 KB Output is correct
20 Correct 22 ms 832 KB Output is correct
21 Correct 63 ms 1108 KB Output is correct
22 Correct 68 ms 1460 KB Output is correct
23 Correct 32 ms 724 KB Output is correct
24 Correct 1 ms 576 KB Output is correct
25 Correct 32 ms 724 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 42 ms 724 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Incorrect 31 ms 724 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 118 ms 1876 KB Output is correct
37 Correct 89 ms 1236 KB Output is correct
38 Correct 22 ms 832 KB Output is correct
39 Correct 63 ms 1108 KB Output is correct
40 Correct 68 ms 1460 KB Output is correct
41 Correct 32 ms 724 KB Output is correct
42 Correct 1 ms 576 KB Output is correct
43 Correct 32 ms 724 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 42 ms 724 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Incorrect 31 ms 724 KB Output isn't correct
48 Halted 0 ms 0 KB -