제출 #578934

#제출 시각아이디문제언어결과실행 시간메모리
578934Mazaalai로봇 (IOI13_robots)C++17
39 / 100
981 ms65536 KiB
#include "robots.h" #include <bits/stdc++.h> #define ub upper_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); } }; struct Toy2 { int w, sz, id; bool operator < (const Toy2& a) const { return mp(sz, w) < mp(a.sz, a.w); } }; int putaway(int weak, int small, int n, int wLimit[], int szLimit[], int w[], int sz[]) { sort(wLimit, wLimit+weak); sort(szLimit, szLimit+small); multiset <Toy1> toys1; multiset <Toy2> toys2; for (int i = 0; i < n; i++) { toys1.insert({w[i], sz[i], i}); toys2.insert({w[i], sz[i], i}); } bool removed[n]; memset(removed, 0, sizeof(removed)); int ans = 0, removeCnt = 0; while(removeCnt < n) { // cout << LINE; // for (auto el : toys1) { // if (removed[el.id]) continue; // cout << el.w << ' ' << el.sz << ' ' << el.id << '\n'; // } ans++; bool curRemoved = 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--; int id = it->id; toys1.erase(it); if (!removed[id]) { removed[id] = 1; curRemoved = 1; removeCnt++; break; } } } Toy2 toy2 = {0, 0, 0}; for (int i = 0; i < small; i++) { toy2.sz = szLimit[i]; while(!toys2.empty()) { auto it = toys2.ub(toy2); if (it == toys2.begin()) break; it--; int id = it->id; toys2.erase(it); if (!removed[id]) { removed[id] = 1; curRemoved = 1; removeCnt++; break; } } } if (!curRemoved) return -1; } return ans; }
#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...