Submission #787831

#TimeUsernameProblemLanguageResultExecution timeMemory
787831drdilyorRobots (IOI13_robots)C++17
28 / 100
1638 ms18392 KiB
#include "robots.h" #include <algorithm> #include <cstring> #include <functional> #include <iostream> #include <cassert> #include <numeric> #include <queue> #include <set> using namespace std; int putaway(int wrobot, int srobot, int n, int rw[], int rs[], int w[], int s[]) { sort(rw, rw + wrobot); sort(rs, rs + srobot); auto comp_w = [&](int i, int j)->bool{ return w[i] < w[j]; }; auto comp_s = [&](int i, int j)->bool{ return s[i] < s[j]; }; int* byw = new int[n]; int* bys = new int[n]; iota(byw, byw + n, 0); iota(bys, bys + n, 0); sort(byw, byw + n, comp_w); sort(bys, bys + n, comp_s); int* done = new int[n]; auto check = [&](int time)->bool { memset(done, 0, sizeof(*done)*n); { int toy = 0; priority_queue<pair<int,int>> st; for (int rob = 0; rob < wrobot; rob++) { while (toy < n && w[byw[toy]] < rw[rob]) { st.emplace(-s[byw[toy]], byw[toy]); toy++; } for (int rem = 0; rem < time && st.size(); rem++) { done[st.top().second] = 1; st.pop(); } } } { int toy = 0; priority_queue<pair<int,int>> st; for (int rob = 0; rob < srobot; rob++) { while (toy < n && s[bys[toy]] < rs[rob]) { if (!done[bys[toy]]) st.emplace(-w[bys[toy]], bys[toy]); toy++; } for (int rem = 0; rem < time && st.size(); rem++) { done[st.top().second] = 1; st.pop(); } } } int all_done = accumulate(done, done + n, 1, bit_and<>()); return all_done; }; int l = -1, r = n +1; while (l < r - 1) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } return r == n+1 ? -1 : r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...