이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "robots.h"
//#include "grader.h"
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long int ll;
const double pi = acos(-1);
const int MOD = 1e9 + 9;
const int INF = 1e9 + 7;
const int MAXN = 3e5 + 5;
const double eps = 1e-9;
int x[MAXN], y[MAXN], vis[MAXN];
pii arr[MAXN], narr[MAXN];
int a, b, t;
bool ok(int cnt) {
//cout << cnt << "\n";
memset(vis, 0, sizeof vis);
int n = 0;
for (int i = t - 1, it = a-1; it >= 0 && i >= 0; it--) {
int j = i, nx = i, cur = 0;
//cout << it << " : ";
while (j >= 0 && cur < cnt) {
//cout << x[it] << " " << arr[j].fi << " " << arr[j].se << " " <<j << " ";
if (x[it] > arr[j].fi)
cur++, vis[j] = 1, nx = j - 1;
else
narr[n++] = {arr[j].se, j};
j--;
}
//cout << "\n";
i = nx;
while (it == 0 && i >= 0)
narr[n++] = {arr[j].se, i--};
}
for (int i = 0; a == 0 && i < t; i++)
narr[n++] = {arr[i].se, i};
sort(narr, narr + n);
/*for (int i =0; i < t; i++)
cout << vis[i] << " ";
cout << "\n";
for (int i =0; i < n; i++)
cout << narr[i].fi << " " << narr[i].se << " ";
cout << "\n";*/
for (int i = n - 1, it = b-1; it >= 0 && i >= 0; it--) {
int j = i, nx = i, cur = 0;
while (j >= 0 && cur <= cnt) {
if (y[it] > narr[j].fi)
cur++, vis[narr[j].se] = 1, nx = j - 1;
j--;
}
i = nx;
}
/*for (int i =0; i < t; i++)
cout << vis[i] << " ";
cout << "\n";*/
for (int i = 0; i < t; i++)
if (!vis[i])
return false;
return true;
}
//w<x;s<y
int putaway(int A, int B, int T, int X[], int Y[], int w[], int s[]) {
a = A, b = B, t = T;
int mxX = 0, mxY = 0;
for (int i = 0; i < a; i++) {
x[i] = X[i];
mxX = max(mxX, X[i]);
}
sort(x, x + a);
for (int i = 0; i < b; i++) {
y[i] = Y[i];
mxY = max(mxY, Y[i]);
}
sort(y, y + b);
for (int i = 0; i < t; i++) {
arr[i] = {w[i], s[i]};
if (w[i] >= mxX && s[i] >= mxY)
return -1;
}
sort(arr, arr + t);
int lo = 1, hi = t, ret = t;
while (lo <= hi) {
int mi = (lo + hi) / 2;
if (ok(mi))
hi = mi - 1, ret = mi;
else
lo = mi + 1;
}
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |