# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
870864 | LOLOLO | 로봇 (IOI13_robots) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e6 + 100;
bool used[N];
vector <vector <int>> save;
int re = 0;
void process(int m, vector <int> &x) {
mem(used, 0);
int j = 0;
priority_queue <pair <int, int>> pq;
for (auto t : x) {
while (j < sz(save) && save[j][0] < t) {
pq.push({save[j][1], save[j][2]});
j++;
}
for (int i = 0; i < m; i++) {
if (pq.empty())
break;
auto t = pq.top();
used[t.s] = 1;
re--;
pq.pop();
}
}
}
bool check(int m, vector <int> &y, vector <int> &need) {
int j = 0, cnt = 0, v = 0;
for (auto x : y) {
while (j < sz(need) && need[j] < x) {
j++;
v++;
}
cnt += min(m, v);
v -= min(v, m);
}
return cnt == sz(need);
}
int putaway(int a, int b, int t, vector <int> x, vector <int> y, vector <int> w, vector <int> s) {
for (int i = 0; i < t; i++) {
save.pb({w[i], s[i], i});
}
sort(all(x));
sort(all(y));
sort(all(save));
int l = 1, r = t, m, ans = -1;
while (l <= r) {
m = (l + r) / 2;
re = t;
process(m, x);
vector <int> need;
for (int i = 0; i < t; i++) {
if (used[i] == 0) {
need.pb(s[i]);
}
}
sort(all(need));
if (check(m, y, need)) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
return ans;
}
/*int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << putaway(3, 2, 10, {6, 2, 9}, {4, 7}, {4,8,2,7,1,5,3,8,7,10}, {6,5,3,9,8,1,3,7,6,5}) << '\n';
}*/