Submission #729709

#TimeUsernameProblemLanguageResultExecution timeMemory
729709Blistering_BarnaclesRobots (IOI13_robots)C++11
100 / 100
1776 ms35132 KiB
#include "robots.h" #include<bits/stdc++.h> using namespace std; int a[50005] , b[50005], m, n ; bool dp[1000005] ; pair < int , int > c1[1000005] , c2[1000005] ; pair < int , int > op[1000005] ; int n1 , n2 ; bool ok(int cnt){ memset(dp , 0 , sizeof dp) ; priority_queue < pair < int , int > > se ; int j = 0 ; m = n ; for(int i = 0 ; i < n1 ; i++){ while(j < n){ if(c1[j].first >= a[i])break ; if(dp[c1[j].second]){ j++ ; continue ; } se.push({op[c1[j].second].second , c1[j].second}) ; j++ ; } int cur = cnt ; while(cur > 0 && !se.empty()){ dp[se.top().second] = 1 ; se.pop() ; m-- ; cur-- ; } if(!m)return 1 ; } j = 0 ; for(int i = 0 ; i < n2 ; i++){ int cur = cnt ; while(j < n && cur > 0){ if(c2[j].first >= b[i])break ; if(dp[c2[j].second]){ j++ ; continue ; } cur-- , m-- ; j++ ; } if(!m)return 1 ; } return 0 ; } bool okn2(int cnt){ int j = 0 ; for(int i = 0 ; i < n1 ; i++){ int cur = cnt ; while(j < n && cur > 0 && a[i] > c1[j].first){ cur-- ; j++ ; } } return (j == n) ; } int putaway(int A, int bb, int T, int X[], int Y[], int W[], int S[]) { n = T ; n1 = A , n2 = bb ; for(int i = 0 ; i < T ; i++){ c1[i] = {W[i] , i} ; c2[i] = {S[i] , i} ; op[i] = {W[i] , S[i]} ; } for(int i = 0 ; i < n1 ; i++){ a[i] = X[i] ; } for(int i = 0 ; i < n2 ; i++){ b[i] = Y[i] ; } sort(c1 , c1 + T) ; sort(c2 , c2 + T) ; if(n1 > 0)sort(a , a + A) ; if(n2 > 0)sort(b , b + bb) ; if(!ok(n))return -1 ; if(!n2){ int l = 0 , r = T + 1 ; while(r - l > 1){ int mid = (l + r) / 2 ; if(okn2(mid))r = mid ; else l = mid ; } return r ; } int l = 1 , r = T , ans ; while(l <= r){ int mid = (l + r) / 2 ; if(ok(mid))r = mid - 1 , ans = mid ; else l = mid + 1 ; } return ans ; }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:88:25: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |     int l = 1 , r = T , 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...