답안 #253767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253767 2020-07-28T16:17:58 Z Sorting Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
62 ms 42360 KB
#include <bits/stdc++.h>

using namespace std;

const int k_N = 200 + 3;

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

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

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

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

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;
        if(!in_q[pos1][pos2][which][cnt]){
            pq.push({pos1, pos2, which, cnt});
            in_q[pos1][pos2][which][cnt] = true;
        }
    }
}

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});
    dist[0][n + 1][false][0] = 0;
    in_q[0][n + 1][false][0] = true;

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

        int time = dist[pos1][pos2][which][cnt];
        in_q[pos1][pos2][which][cnt] = false;

        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:52:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
         auto [pos1, pos2, which, cnt] = pq.front();
              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 0 ms 640 KB Output is correct
7 Correct 0 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 0 ms 640 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 0 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 0 ms 640 KB Output is correct
7 Correct 0 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 0 ms 640 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 0 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Correct 1 ms 640 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 768 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 768 KB Output is correct
30 Correct 1 ms 896 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 768 KB Output is correct
34 Correct 1 ms 768 KB Output is correct
35 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 0 ms 640 KB Output is correct
7 Correct 0 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 0 ms 640 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 0 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Correct 28 ms 33016 KB Output is correct
19 Correct 18 ms 20992 KB Output is correct
20 Correct 8 ms 11392 KB Output is correct
21 Correct 16 ms 19584 KB Output is correct
22 Correct 20 ms 24576 KB Output is correct
23 Correct 7 ms 9728 KB Output is correct
24 Correct 4 ms 6400 KB Output is correct
25 Correct 7 ms 9600 KB Output is correct
26 Correct 2 ms 3456 KB Output is correct
27 Correct 7 ms 9856 KB Output is correct
28 Correct 4 ms 6272 KB Output is correct
29 Correct 9 ms 10112 KB Output is correct
30 Correct 4 ms 6656 KB Output is correct
31 Correct 9 ms 9600 KB Output is correct
32 Correct 4 ms 4992 KB Output is correct
33 Correct 8 ms 9472 KB Output is correct
34 Correct 2 ms 3072 KB Output is correct
35 Correct 9 ms 8960 KB Output is correct
36 Correct 2 ms 3968 KB Output is correct
37 Correct 8 ms 9728 KB Output is correct
38 Correct 4 ms 5632 KB Output is correct
39 Correct 7 ms 10368 KB Output is correct
40 Correct 4 ms 5248 KB Output is correct
41 Correct 27 ms 39548 KB Output is correct
42 Correct 14 ms 23808 KB Output is correct
43 Correct 27 ms 39544 KB Output is correct
44 Correct 14 ms 23552 KB Output is correct
45 Correct 31 ms 39544 KB Output is correct
46 Correct 15 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 0 ms 640 KB Output is correct
7 Correct 0 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 0 ms 640 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 0 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Correct 1 ms 640 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 768 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 768 KB Output is correct
30 Correct 1 ms 896 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 768 KB Output is correct
34 Correct 1 ms 768 KB Output is correct
35 Correct 1 ms 768 KB Output is correct
36 Correct 28 ms 33016 KB Output is correct
37 Correct 18 ms 20992 KB Output is correct
38 Correct 8 ms 11392 KB Output is correct
39 Correct 16 ms 19584 KB Output is correct
40 Correct 20 ms 24576 KB Output is correct
41 Correct 7 ms 9728 KB Output is correct
42 Correct 4 ms 6400 KB Output is correct
43 Correct 7 ms 9600 KB Output is correct
44 Correct 2 ms 3456 KB Output is correct
45 Correct 7 ms 9856 KB Output is correct
46 Correct 4 ms 6272 KB Output is correct
47 Correct 9 ms 10112 KB Output is correct
48 Correct 4 ms 6656 KB Output is correct
49 Correct 9 ms 9600 KB Output is correct
50 Correct 4 ms 4992 KB Output is correct
51 Correct 8 ms 9472 KB Output is correct
52 Correct 2 ms 3072 KB Output is correct
53 Correct 9 ms 8960 KB Output is correct
54 Correct 2 ms 3968 KB Output is correct
55 Correct 8 ms 9728 KB Output is correct
56 Correct 4 ms 5632 KB Output is correct
57 Correct 7 ms 10368 KB Output is correct
58 Correct 4 ms 5248 KB Output is correct
59 Correct 27 ms 39548 KB Output is correct
60 Correct 14 ms 23808 KB Output is correct
61 Correct 27 ms 39544 KB Output is correct
62 Correct 14 ms 23552 KB Output is correct
63 Correct 31 ms 39544 KB Output is correct
64 Correct 15 ms 23808 KB Output is correct
65 Correct 39 ms 36216 KB Output is correct
66 Correct 28 ms 33784 KB Output is correct
67 Correct 24 ms 31744 KB Output is correct
68 Correct 25 ms 29560 KB Output is correct
69 Correct 34 ms 36728 KB Output is correct
70 Correct 36 ms 34720 KB Output is correct
71 Correct 20 ms 30592 KB Output is correct
72 Correct 38 ms 35324 KB Output is correct
73 Correct 17 ms 28032 KB Output is correct
74 Correct 28 ms 30840 KB Output is correct
75 Correct 19 ms 30336 KB Output is correct
76 Correct 62 ms 38904 KB Output is correct
77 Correct 21 ms 34300 KB Output is correct
78 Correct 43 ms 30072 KB Output is correct
79 Correct 19 ms 29056 KB Output is correct
80 Correct 58 ms 37624 KB Output is correct
81 Correct 17 ms 27776 KB Output is correct
82 Correct 36 ms 32248 KB Output is correct
83 Correct 24 ms 36736 KB Output is correct
84 Correct 39 ms 34552 KB Output is correct
85 Correct 20 ms 32000 KB Output is correct
86 Correct 42 ms 36168 KB Output is correct
87 Correct 24 ms 32512 KB Output is correct
88 Correct 37 ms 42360 KB Output is correct
89 Correct 27 ms 39800 KB Output is correct
90 Correct 17 ms 29568 KB Output is correct
91 Correct 40 ms 42104 KB Output is correct
92 Correct 30 ms 40064 KB Output is correct
93 Correct 20 ms 34296 KB Output is correct