제출 #964955

#제출 시각아이디문제언어결과실행 시간메모리
964955Acanikolic로봇 (IOI13_robots)C++14
53 / 100
568 ms31964 KiB
#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 = max(A,B),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 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...