Submission #290170

#TimeUsernameProblemLanguageResultExecution timeMemory
290170Atill83Robots (IOI13_robots)C++14
100 / 100
2853 ms58628 KiB
#include "robots.h" #include <bits/stdc++.h> using namespace std; int a, b, *x, *y, *w, *s, t; vector<int> vc; const int MAXN = (int) 2e6 + 5; const int MAXM = (int) 5e4 + 5; bool done[MAXN]; long long kal[MAXN]; int par[MAXN]; int find_set(int v){ if(kal[v]) return v; else return par[v] = find_set(par[v]); } bool check(int d){ memset(done, 0, sizeof(done)); memset(kal, 0, sizeof(kal)); int last = 0; for(int i = 0; i <= t + b + 50; i++){ par[i] = MAXN - 1; } kal[MAXN - 1] = (long long) 1e18; for(int i = 0; i < b; i++){ kal[y[i]] += d; for(int j = last; j < y[i]; j++){ par[j] = y[i]; } last = y[i]; } for(int j = t - 1; j >= 0; j--){ int cur = vc[j]; int u = find_set(par[s[cur]]); if(u == MAXN - 1) continue; else{ done[j] = 1; kal[u]--; } } int pt2 = a - 1, used = d; for(int j = t - 1; j >= 0; j--){ if(done[j]) continue; int cur = vc[j]; if(pt2 == -1 || x[pt2] <= w[cur]) return 0; used--; if(used == 0){ pt2--; used = d; } } return 1; } map<int, int> mp; set<int> st; int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { if(B > A){ swap(X, Y); swap(W, S); swap(A, B); } a = A; b = B; x = X; y = Y; w = W; s = S; t = T; for(int i = 0; i < T; i++) st.insert(S[i]); for(int i = 0; i < B; i++) st.insert(Y[i]); int cnt = 1; for(int i: st){ mp[i] = cnt++; } for(int i = 0; i < T; i++) S[i] = mp[S[i]]; for(int i = 0; i < B; i++) Y[i] = mp[Y[i]]; st.clear(); mp.clear(); sort(X, X + A); sort(Y, Y + B); //cout<<ali[0]<<endl; for(int i = 0; i < T; i++) vc.push_back(i); sort(vc.begin(), vc.end(), [W](int a, int b){ return W[a] < W[b]; }); for(int j = vc.size() - 1; j >= 0; j--){ if(W[vc[j]] < X[A - 1]) break; if(B == 0 || S[vc[j]] >= Y[B - 1]) return -1; } int l = 1, r = T; while(l < r){ int m = (l + r) / 2; if(check(m)){ r = m; }else{ l = m + 1; } } return l; }
#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...