Submission #383981

#TimeUsernameProblemLanguageResultExecution timeMemory
383981KeshiRobots (IOI13_robots)C++17
100 / 100
2896 ms35024 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 = 5e4 + 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; //pll ss[maxm]; vector<ll> v1[maxn], v2[maxn]; bitset<maxm> ok; bool check(ll e, ll s[]){ ok.reset(); set<pll> st; // cout << "# " << e << "\n"; for(ll i = 0; i < a; i++){ for(ll j : v1[i]){ st.insert(Mp(-s[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; 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"; //ss[i] = Mp(s[i], i); v1[w[i]].pb(i); v2[s[i]].pb(i); } /*sort(ss, ss + t); for(ll i = 0; i < t; i++){ v1[w[ss[i].S]].pb(ss[i].S); }*/ ll l = 0, r = t, mid; while(r - l > 1){ mid = (l + r) >> 1; if(check(mid, s)) r = mid; else l = mid; } return r; } /*int main(){ freopen("sample1.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...