# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
578967 | Mazaalai | 로봇 (IOI13_robots) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define ff first
#define ss second
#define LINE "--------------------\n"
using namespace std;
using PII = pair <int, int>;
int n, m, k, a, b;
const int N = 5e4+5;
const int M = 1e6+5;
int wLimit[N], szLimit[N];
int w[M], sz[M];
bool removed[N];
struct Toy {
int w, sz, id;
bool operator < (const Toy& a) const {
return mp(w, sz) > mp(a.w, a.sz);
}
};
bool solve(int lim) {
multiset <PII, greater<PII> > vals, vals1;
for (int i = 0; i < n; i++) vals.insert({w[i], sz[i]});
for (int i = a-1; i >= 0; i--) {
for (int j = 0; j < lim && !vals.empty(); j++) {
while(!vals.empty()) {
auto it = vals.begin();
PII tmp = *it;
if (wLimit[i] <= tmp.ff) {
vals.erase(it);
// cout << "LEAVE: " << tmp.ff << ' ' << tmp.ss << '\n';
vals1.insert({tmp.ss, tmp.ff});
continue;
}
break;
}
if (!vals.empty()) {
// cout << wLimit[i] << ": " << vals.begin()->ff << ',' << vals.begin()->ss << '\n';
vals.erase(vals.begin());
}
}
}
for (auto& [x, y] : vals) {
// cout << "LEAVE: " << x << ',' << y << '\n';
vals1.insert({y, x});
}
// cout << "HERE: ";
// for (auto& [x, y] : vals1) {
// cout << y << ',' << x << ' ';
// }
// cout << '\n';
for (int i = b-1; i >= 0; i--) {
for (int j = 0; j < lim && !vals1.empty(); j++) {
while(!vals1.empty()) {
auto it = vals1.begin();
PII tmp = *it;
if (szLimit[i] <= tmp.ff) return 0;
break;
}
if (!vals1.empty()) {
// cout << szLimit[i] << ": " << vals1.begin()->ss << ',' << vals1.begin()->ff << '\n';
vals1.erase(vals1.begin());
}
}
}
return vals1.size() == 0;
}
int putaway(int weak, int small, int _n, int _wLimit[], int _szLimit[], int _w[], int _sz[]) {
n = _n;
if (weak > 0) sort(_wLimit, _wLimit+weak);
if (small > 0) sort(_szLimit, _szLimit+small);
a = weak;
b = small;
for (int i = 0; i < weak; i++) wLimit[i] = _wLimit[i];
for (int i = 0; i < small; i++) szLimit[i] = _szLimit[i];
for (int i = 0; i < n; i++) w[i] = _w[i], sz[i] = _sz[i];
if (n == 0) return 0;
int l = 1, r = , ans = 1e9;
while (l <= r) {
int mid = (l+r)>>1;
if (solve(mid)) {
r = mid-1;
ans = mid;
} else {
l = mid+1;
}
}
return ans == 1e9 ? -1 : ans;
}