Submission #253759

# Submission time Handle Problem Language Result Execution time Memory
253759 2020-07-28T16:08:11 Z Sorting Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
365 ms 34924 KB
#include <bits/stdc++.h>

using namespace std;

const int k_N = 200 + 3;

struct Node{
    int pos1, pos2;
    bool which;
    int cnt;
    int time;

    Node(){}
    Node(int pos1, int pos2, bool which, int cnt, int time){
        this->pos1 = pos1;
        this->pos2 = pos2;
        this->which = which;
        this->cnt = cnt;
        this->time = time;
    }

    friend bool operator<(const Node &lvalue, const Node &rvalue){
        return lvalue.time > rvalue.time;
    }
};

int n, l, x[k_N], t[k_N];
int max_t = 0;

int dist[k_N][k_N][2][k_N];
int ans = 0;

priority_queue<Node> pq;

void try_add(int pos1, int pos2, bool which, int cnt, int time){
    if(dist[pos1][pos2][which][cnt] > time){
        dist[pos1][pos2][which][cnt] = time;
        pq.push({pos1, pos2, which, cnt, time});
    }
}

void dijkstra(){
    for(int pos1 = 0; pos1 <= n + 1; ++pos1)
        for(int pos2 = pos1; pos2 <= n + 1; ++pos2)
            for(short which = 0; which <= 1; ++which)
                for(int cnt = 0; cnt <= n; ++cnt)
                    dist[pos1][pos2][which][cnt] = max_t;

    pq.push({0, n + 1, false, 0, 0});
    dist[0][n + 1][false][0] = 0;

    while(!pq.empty()){
        auto [pos1, pos2, which, cnt, time] = pq.top();
        pq.pop();

        if(time >= max_t) break;
        if(dist[pos1][pos2][which][cnt] != time)
            continue;

        ans = max(ans, cnt);

        if(pos1 + 1 == pos2) continue;

        int new_pos1, new_pos2, new_which, new_cnt, new_time;

        if(!which){
            new_time = time + x[pos1 + 1] - x[pos1];
            new_cnt = cnt + (new_time <= t[pos1 + 1]);
            new_pos1 = pos1 + 1;
            new_pos2 = pos2;
            new_which = false;

            try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
        }
        else{
            new_time = time + x[pos2] - x[pos2 - 1];
            new_cnt = cnt + (new_time <= t[pos2 - 1]);
            new_pos1 = pos1;
            new_pos2 = pos2  - 1;
            new_which = true;

            try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
        }

        if(!which){
            new_time = time + x[pos1] + l - x[pos2 - 1];
            new_cnt = cnt + (new_time <= t[pos2 - 1]);
            new_pos1 = pos1;
            new_pos2 = pos2 - 1;
            new_which = true;

            try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
        }
        else{
            new_time = time + x[pos1 + 1] + l - x[pos2];
            new_cnt = cnt + (new_time <= t[pos1 + 1]);
            new_pos1 = pos1 + 1;
            new_pos2 = pos2;
            new_which = false;

            try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> l;

    x[0] = 0;
    for(int i = 1; i <= n; ++i)
        cin >> x[i];
    x[n + 1] = l;

    t[0] = 0;
    for(int i = 1; i <= n; ++i){
        cin >> t[i];
        max_t = max(max_t, t[i]);
    }
    t[n + 1] = 0;

    max_t++;
    dijkstra();
    //ans -= 2;

    cout << ans << "\n";
}

Compilation message

ho_t3.cpp: In function 'void dijkstra()':
ho_t3.cpp:53:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
         auto [pos1, pos2, which, cnt, time] = pq.top();
              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 0 ms 640 KB Output is correct
19 Correct 0 ms 512 KB Output is correct
20 Correct 0 ms 512 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 0 ms 512 KB Output is correct
23 Correct 1 ms 640 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 1 ms 640 KB Output is correct
26 Correct 1 ms 640 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 640 KB Output is correct
32 Correct 1 ms 640 KB Output is correct
33 Correct 1 ms 640 KB Output is correct
34 Correct 1 ms 640 KB Output is correct
35 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 51 ms 28084 KB Output is correct
19 Correct 29 ms 17248 KB Output is correct
20 Correct 10 ms 9472 KB Output is correct
21 Correct 21 ms 16224 KB Output is correct
22 Correct 29 ms 20960 KB Output is correct
23 Correct 11 ms 8288 KB Output is correct
24 Correct 5 ms 6272 KB Output is correct
25 Correct 11 ms 8064 KB Output is correct
26 Correct 2 ms 3328 KB Output is correct
27 Correct 15 ms 8416 KB Output is correct
28 Correct 5 ms 5888 KB Output is correct
29 Correct 17 ms 8800 KB Output is correct
30 Correct 5 ms 6656 KB Output is correct
31 Correct 20 ms 8288 KB Output is correct
32 Correct 3 ms 4352 KB Output is correct
33 Correct 15 ms 8288 KB Output is correct
34 Correct 2 ms 3072 KB Output is correct
35 Correct 10 ms 7936 KB Output is correct
36 Correct 2 ms 3840 KB Output is correct
37 Correct 11 ms 8544 KB Output is correct
38 Correct 5 ms 4736 KB Output is correct
39 Correct 15 ms 8928 KB Output is correct
40 Correct 3 ms 5120 KB Output is correct
41 Correct 35 ms 33760 KB Output is correct
42 Correct 13 ms 22784 KB Output is correct
43 Correct 28 ms 33664 KB Output is correct
44 Correct 14 ms 22528 KB Output is correct
45 Correct 28 ms 33664 KB Output is correct
46 Correct 15 ms 22784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 0 ms 640 KB Output is correct
19 Correct 0 ms 512 KB Output is correct
20 Correct 0 ms 512 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 0 ms 512 KB Output is correct
23 Correct 1 ms 640 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 1 ms 640 KB Output is correct
26 Correct 1 ms 640 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 640 KB Output is correct
32 Correct 1 ms 640 KB Output is correct
33 Correct 1 ms 640 KB Output is correct
34 Correct 1 ms 640 KB Output is correct
35 Correct 1 ms 640 KB Output is correct
36 Correct 51 ms 28084 KB Output is correct
37 Correct 29 ms 17248 KB Output is correct
38 Correct 10 ms 9472 KB Output is correct
39 Correct 21 ms 16224 KB Output is correct
40 Correct 29 ms 20960 KB Output is correct
41 Correct 11 ms 8288 KB Output is correct
42 Correct 5 ms 6272 KB Output is correct
43 Correct 11 ms 8064 KB Output is correct
44 Correct 2 ms 3328 KB Output is correct
45 Correct 15 ms 8416 KB Output is correct
46 Correct 5 ms 5888 KB Output is correct
47 Correct 17 ms 8800 KB Output is correct
48 Correct 5 ms 6656 KB Output is correct
49 Correct 20 ms 8288 KB Output is correct
50 Correct 3 ms 4352 KB Output is correct
51 Correct 15 ms 8288 KB Output is correct
52 Correct 2 ms 3072 KB Output is correct
53 Correct 10 ms 7936 KB Output is correct
54 Correct 2 ms 3840 KB Output is correct
55 Correct 11 ms 8544 KB Output is correct
56 Correct 5 ms 4736 KB Output is correct
57 Correct 15 ms 8928 KB Output is correct
58 Correct 3 ms 5120 KB Output is correct
59 Correct 35 ms 33760 KB Output is correct
60 Correct 13 ms 22784 KB Output is correct
61 Correct 28 ms 33664 KB Output is correct
62 Correct 14 ms 22528 KB Output is correct
63 Correct 28 ms 33664 KB Output is correct
64 Correct 15 ms 22784 KB Output is correct
65 Correct 51 ms 31028 KB Output is correct
66 Correct 62 ms 28604 KB Output is correct
67 Correct 43 ms 27172 KB Output is correct
68 Correct 35 ms 25184 KB Output is correct
69 Correct 53 ms 30780 KB Output is correct
70 Correct 123 ms 30192 KB Output is correct
71 Correct 17 ms 29056 KB Output is correct
72 Correct 101 ms 30140 KB Output is correct
73 Correct 15 ms 27264 KB Output is correct
74 Correct 96 ms 27000 KB Output is correct
75 Correct 18 ms 28160 KB Output is correct
76 Correct 365 ms 34924 KB Output is correct
77 Correct 20 ms 32256 KB Output is correct
78 Correct 237 ms 26456 KB Output is correct
79 Correct 23 ms 26112 KB Output is correct
80 Correct 357 ms 34280 KB Output is correct
81 Correct 15 ms 26112 KB Output is correct
82 Correct 180 ms 30316 KB Output is correct
83 Correct 24 ms 33536 KB Output is correct
84 Correct 195 ms 31468 KB Output is correct
85 Correct 17 ms 31232 KB Output is correct
86 Correct 223 ms 33260 KB Output is correct
87 Correct 39 ms 28640 KB Output is correct
88 Correct 83 ms 34620 KB Output is correct
89 Correct 31 ms 34040 KB Output is correct
90 Correct 20 ms 28544 KB Output is correct
91 Correct 102 ms 34612 KB Output is correct
92 Correct 39 ms 34048 KB Output is correct
93 Correct 19 ms 33152 KB Output is correct