Submission #253767

#TimeUsernameProblemLanguageResultExecution timeMemory
253767SortingCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
62 ms42360 KiB
#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 (stderr)

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();
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...