Submission #1004708

#TimeUsernameProblemLanguageResultExecution timeMemory
1004708ProtonDecay314로봇 (IOI13_robots)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> // #define DEBUG using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vi; vi to_vec(int arr[], int sz) { vi res(sz, 0); for(int i = 0; i < sz; i++) { res[i] = arr[i]; } return res; } struct toy { int w; int s; int wi; int si; bool operator<(const toy& other) const { return si < other.si; } }; int get_flimsiest_robot(const vi& robots, int val) { int l = -1, r = robots.size(); while(r - l > 1) { int m = (l + r) >> 1; if(robots[m] > val) r = m; else l = m; } return r; } bool poss(const vector<toy>& toys, int a, int b, int t, int d) { // Check if possible for a certain max duration d int cur_added = 0; priority_queue<toy> q; int p1 = 0, p2 = 0; for(int i = 0; i < a; i++) { #ifdef DEBUG cout << "POINTERS: " << p1 << " " << p2 << endl; #endif // Move pointer 1 to the first toy whose wi equals i while(p1 < t && toys[p1].wi < i) p1++; // ! oop, I did toys[p1].wi > i haha p2 = p1; while(p2 < t && toys[p2].wi <= i) p2++; // Add these new toys to the priority queue for(int j = p1; j < p2; j++) { q.push(toys[j]); } // Assign "d" of these toys to the current weak robot wr[i] // (i.e., pop d times from the priority queue) for(int j = 0; j < d; j++) { if(q.empty()) break; #ifdef DEBUG cout << q.top().si << endl; #endif q.pop(); } } // Push the toys that cannot be handled by any weak robot // These can potentially be handled by small robots though for(int i = p2; i < t; i++) { q.push(toys[i]); } // Now, we've assigned some toys to the weak robots // We now assign the rest to the small robots #ifdef DEBUG cout << "NUM TOYS TO SMALL: " << q.size() << endl; #endif if(q.empty()) return true; int cur_ind = b - 1; while(cur_ind >= 0) { if(q.top().si > cur_ind) return false; for(int i = 0; i < d; i++) { if(q.empty()) return true; q.pop(); } if(q.empty()) return true; cur_ind--; } return q.empty(); } // IOI Function Signatures int putaway(int a, int b, int t, int xarr[], int yarr[], int warr[], int sarr[]) { // x is weight, y is size vi x = to_vec(xarr, a), y = to_vec(yarr, b); // Sorting robots sort(x.begin(), x.end()); sort(y.begin(), y.end()); // Storing Toys vector<toy> toys; toys.reserve(t); for(int i = 0; i < t; i++) { toys.push_back({warr[i], sarr[i], 0, 0}); } // Binary searching to get the index of the first robot that can handle this for(int i = 0; i < t; i++) { toys[i].wi = get_flimsiest_robot(x, toys[i].w); toys[i].si = get_flimsiest_robot(x, toys[i].s); // No robot can pick this up, return -1 if(toys[i].wi == a && toys[i].si == b) return -1; } // Sort the toys, first from lightest to heaviest, then largest to smallest sort(toys.begin(), toys.end(), [](toy a, toy b) { return a.wi < b.wi || (a.wi == b.wi && a.si > b.si); }); int l = 0, r = t + 1; while(r - l > 1) { int m = (l + r) >> 1; if(poss(toys, a, b, t, m)) r = m; else l = m; } return r; };

Compilation message (stderr)

robots.cpp: In function 'bool poss(const std::vector<toy>&, int, int, int, int)':
robots.cpp:42:9: warning: unused variable 'cur_added' [-Wunused-variable]
   42 |     int cur_added = 0;
      |         ^~~~~~~~~
/usr/bin/ld: /tmp/ccVqZB2r.o: in function `main':
grader.c:(.text.startup+0x1b1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status