Submission #383974

#TimeUsernameProblemLanguageResultExecution timeMemory
383974KeshiRobots (IOI13_robots)C++17
39 / 100
251 ms36968 KiB
//In the name of God #include <bits/stdc++.h> #include "robots.h" using namespace std; typedef int ll; typedef pair<ll, ll> pll; const ll maxn = 1e5 + 100; const ll maxm = 1e6 + 100; const ll mod = 1e9 + 7; const ll inf = 1e9; #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout); #define pb push_back #define Mp make_pair #define F first #define S second #define Sz(x) ll((x).size()) #define all(x) (x).begin(), (x).end() ll a, b, t, x[maxn], y[maxn], w[maxm], s[maxm]; pll ww[maxn], ss[maxn]; vector<ll> v1[maxn], v2[maxn]; bool ok[maxm]; bool check(ll e){ fill(ok, ok + t, 0); set<pll> st; // cout << "# " << e << "\n"; for(ll i = 0; i < a; i++){ for(ll j : v1[i]){ st.insert(Mp(-w[j], j)); } for(ll j = 0; j < e; j++){ if(st.empty()) break; //cout << "! " << i << " -> " << st.begin()->S << "\n"; ok[st.begin()->S] = 1; st.erase(st.begin()); } } ll cnt = 0; for(ll i = 0; i < b; i++){ for(ll j : v2[i]){ if(!ok[j]) cnt++; } cnt = max(cnt - e, 0); } for(ll j : v2[b]){ if(!ok[j]) cnt++; } return (cnt == 0); } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { a = A; b = B; t = T; for(ll i = 0; i < a; i++){ x[i] = X[i]; } for(ll i = 0; i < b; i++){ y[i] = Y[i]; } sort(x, x + a); sort(y, y + b); for(ll i = 0; i < t; i++){ w[i] = upper_bound(x, x + a, W[i]) - x; s[i] = upper_bound(y, y + b, S[i]) - y; if(w[i] >= a && s[i] >= b) return -1; //cout << i << ": " << w[i] << " " << s[i] << "\n"; ww[i] = Mp(w[i], i); ss[i] = Mp(s[i], i); } //sort(ww, ww + t); sort(ss, ss + t); for(ll i = 0; i < t; i++){ v1[w[ss[i].S]].pb(ss[i].S); v2[s[ww[i].S]].pb(ww[i].S); } ll l = 0, r = t, mid; while(r - l > 1){ mid = (l + r) >> 1; if(check(mid)) r = mid; else l = mid; } return r; } /*int main(){ freopen("sample2.in", "r", stdin); int A, B, T, X[100], Y[100], W[100], S[100]; cin >> A >> B >> T; for(ll i = 0; i < A; i++){ cin >> X[i]; } for(ll i = 0; i < B; i++){ cin >> Y[i]; } for(ll i = 0; i < T; i++){ cin >> W[i] >> S[i]; } cout << putaway(A, B, T, X, Y, W, S); return 0; }*/
#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...