Submission #503000

#TimeUsernameProblemLanguageResultExecution timeMemory
503000kevinRobots (IOI13_robots)C++17
76 / 100
3087 ms22992 KiB
#include "robots.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define nl cout<<"\n" #define s second #define f first #define all(x) x.begin(), x.end() #define ca(v) for(auto i:v) cout<<i<<" "; bool solve(int m, vector<int> &X, vector<int> &Y, vector<pair<int, int>> &T){ multiset<pair<int, int>> st; for(int i:X) st.insert({i, m}); vector<pair<int, int>> P1; vector<pair<int, int>> P2; for(auto p:T) P1.push_back(p); sort(all(P1)); while(P1.size()){ auto c = P1.back(); P1.pop_back(); auto it = st.upper_bound({c.s, m+1}); if(it != st.end()){ auto nxt = *it; st.erase(it); nxt.s--; if(nxt.s) st.insert(nxt); } else{ P2.push_back({c.s, c.f}); } } sort(all(P2)); st.clear(); for(int i:Y) st.insert({i, m}); while(P2.size()){ auto c = P2.back(); P2.pop_back(); auto it = st.upper_bound({c.s, m+1}); if(it != st.end()){ auto nxt = *it; st.erase(it); nxt.s--; if(nxt.s) st.insert(nxt); } else{ return false; } } return true; } int putaway(int A, int B, int N, int x[], int y[], int w[], int s[]){ vector<int> X, Y, W, S; for(int i=0; i<A; i++) X.push_back(x[i]); for(int i=0; i<B; i++) Y.push_back(y[i]); for(int i=0; i<N; i++) W.push_back(w[i]); for(int i=0; i<N; i++) S.push_back(s[i]); sort(all(X)); sort(all(Y)); int mxa = 0; int mxb = 0; for(int i : X) mxa = max(mxa, i); for(int i : Y) mxb = max(mxb, i); for(int i=0; i<N; i++){ if(W[i] >= mxa && S[i] >= mxb) return -1; } int ans = N+1; int l = 1; int r = N; vector<pair<int, int>> T; for(int i=0; i<N; i++) T.push_back({S[i], W[i]}); while(l <= r){ int m = (l + r) / 2; if(solve(m, X, Y, T)){ ans = m; r = m-1; } else l = m+1; } if(ans == N+1) return -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...