Submission #253765

# Submission time Handle Problem Language Result Execution time Memory
253765 2020-07-28T16:11:47 Z Sorting Collecting Stamps 3 (JOI20_ho_t3) C++14
5 / 100
24 ms 31992 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];
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, time});
            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, 0});
    dist[0][n + 1][false][0] = 0;

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

        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:57:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
         auto [pos1, pos2, which, cnt, time] = pq.front();
              ^
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 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 1 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 1 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 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 1 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 1 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Incorrect 1 ms 768 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 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 1 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 1 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Incorrect 24 ms 31992 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 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 1 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 1 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Incorrect 1 ms 768 KB Output isn't correct
19 Halted 0 ms 0 KB -