이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "robots.h"
//#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1000000 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;
bool check(int A,int B,int T,vector<int>X,vector<int>Y,vector<pair<int,int>>W,vector<pair<int,int>>S,int mid) {
vector<bool>vis(T,false);
priority_queue<int>pq;
int ptr = -1;
for(int i = 0; i < T; i++) {
if(pq.empty() && ptr + 1 < A && X[ptr + 1] > W[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(X[ptr + 1]);
}
ptr += 1;
}
if(mid == 3 && i == 1) {
//cout << "debug:" << X[ptr + 1] << " " << W[i].F << " " << W[i].S << endl;
}
if(pq.empty()) continue;
vis[W[i].S] = true;
pq.pop();
}
if(mid == 3) {
//for(int i = 0; i < T; i++) if(vis[i]) cout << "dbg:::" << i << endl;
//cout << endl;
}
while(pq.size()) pq.pop();
ptr = -1;
for(int i = 0; i < T; i++) {
if(vis[S[i].S]) continue;
if(pq.empty() && ptr + 1 < B && Y[ptr + 1] > S[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(Y[ptr + 1]);
}
ptr += 1;
}
if(pq.empty()) continue;
vis[S[i].S] = true;
pq.pop();
}
bool ok = true;
for(int i = 0; i < T; i++) if(!vis[i]) ok = false;
if(mid == 3) {
// for(int i = 0; i < T; i++) if(vis[i]) cout << "dbg:::" << i << endl;
}
if(ok) return true;
while(pq.size()) pq.pop();
for(int i = 0; i < T; i++) vis[i] = false;
ptr = -1;
for(int i = 0; i < T; i++) {
if(pq.empty() && ptr + 1 < B && Y[ptr + 1] > S[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(Y[ptr + 1]);
}
ptr += 1;
}
if(pq.empty()) continue;
vis[S[i].S] = true;
pq.pop();
}
while(pq.size()) pq.pop();
ptr = -1;
for(int i = 0; i < T; i++) {
if(vis[W[i].S]) continue;
if(pq.empty() && ptr + 1 < A && X[ptr + 1] > W[i].F) {
for(int j = 0; j < mid; j++) {
pq.push(X[ptr + 1]);
}
ptr += 1;
}
if(pq.empty()) continue;
vis[W[i].S] = true;
pq.pop();
}
ok = true;
for(int i = 0; i < T; i++) if(!vis[i]) ok = false;
return ok;
}
int putaway(int A, int B, int T, int* x, int* y, int* W, int* S) {
vector<int>X(A);
vector<int>Y(B);
vector<pair<int,int>>w(T);
vector<pair<int,int>>s(T);
for(int i = 0; i < T; i++) {
w[i] = {W[i],i};
s[i] = {S[i],i};
}
for(int i = 0; i < A; i++) X[i] = x[i];
for(int i = 0; i < B; i++) Y[i] = y[i];
sort(X.begin(),X.end());
sort(Y.begin(),Y.end());
sort(w.begin(),w.end());
sort(s.begin(),s.end());
reverse(X.begin(),X.end());
reverse(Y.begin(),Y.end());
reverse(w.begin(),w.end());
reverse(s.begin(),s.end());
int l = 1, r = T,ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(check(A,B,T,X,Y,w,s,mid)) {
ans = mid;
r = mid - 1;
}else {
l = mid + 1;
}
}
return ans;
}
# | 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... |