Submission #578951

#TimeUsernameProblemLanguageResultExecution timeMemory
578951MazaalaiRobots (IOI13_robots)C++17
Compilation error
0 ms0 KiB
#include "robots.h" #include <bits/stdc++.h> #define ub upper_bound #define lb lower_bound #define mp make_pair #define LINE "--------------------\n" using namespace std; int n, m, k; struct Toy1 { int w, sz, id; bool operator < (const Toy1& a) const { return mp(w, sz) < mp(a.w, a.sz); } }; int putaway(int weak, int small, int n, int wLimit[], int szLimit[], int w[], int sz[]) { if (weak > 0) sort(wLimit, wLimit+weak); if (small > 0) sort(szLimit, szLimit+small); multiset <Toy1> toys1, toys2; for (int i = 0; i < n; i++) { toys1.insert({w[i], sz[i], i}); toys2.insert({sz[i], w[i], i}); } int ans = 0, removeCnt = 0; while(removeCnt < n) { // cout << LINE; // for (auto el : toys1) { // cout << el.w << ' ' << el.sz << ' ' << el.id << '\n'; // } // cout << "\n"; // for (auto el : toys2) { // cout << el.w << ' ' << el.sz << ' ' << el.id << '\n'; // } ans++; bool curRemoved = 0; if (weak > 0) { Toy1 toy1 = {0, 0, 0}; for (int i = 0; i < weak; i++) { toy1.w = wLimit[i]; while(!toys1.empty()) { auto it = toys1.ub(toy1); if (it == toys1.begin()) break; it--; if (!it) break; int id = it->id; toys1.erase(it); toys2.erase(toys2.lb({sz[id], w[id], id})); curRemoved = 1; removeCnt++; break; } } } if (small > 0) { Toy1 toy2 = {0, 0, 0}; for (int i = 0; i < small; i++) { toy2.w = szLimit[i]; while(!toys2.empty()) { auto it = toys2.ub(toy2); if (it == toys2.begin()) break; it--; if (!it) break; int id = it->id; toys2.erase(it); toys1.erase(toys1.lb({sz[id], w[id], id})); curRemoved = 1; removeCnt++; break; } } } if (!curRemoved) return -1; } // cout << LINE; // for (auto el : toys1) { // cout << el.w << ' ' << el.sz << ' ' << el.id << '\n'; // } // cout << "\n"; // for (auto el : toys2) { // cout << el.w << ' ' << el.sz << ' ' << el.id << '\n'; // } return ans; }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:43:25: error: no match for 'operator!' (operand type is 'std::_Rb_tree_const_iterator<Toy1>')
   43 |                     if (!it) break;
      |                         ^~~
robots.cpp:43:25: note: candidate: 'operator!(bool)' (built-in)
robots.cpp:43:25: note:   no known conversion for argument 1 from 'std::_Rb_tree_const_iterator<Toy1>' to 'bool'
robots.cpp:61:25: error: no match for 'operator!' (operand type is 'std::_Rb_tree_const_iterator<Toy1>')
   61 |                     if (!it) break;
      |                         ^~~
robots.cpp:61:25: note: candidate: 'operator!(bool)' (built-in)
robots.cpp:61:25: note:   no known conversion for argument 1 from 'std::_Rb_tree_const_iterator<Toy1>' to 'bool'