Submission #131131

#TimeUsernameProblemLanguageResultExecution timeMemory
131131baluteshihRobots (IOI13_robots)C++14
100 / 100
1308 ms24944 KiB
#include "robots.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int n,a,b,x[50005],y[50005];
pii data[1000005];

bool check(int c)
{
	ll sz=0;
	vector<int> v;
	priority_queue<int,vector<int>,greater<int>> pq;
	for(int i=0,nw=a-1;i<n;++i)
	{
		while(nw>=0&&x[nw]>data[i].F)
			--nw,sz+=c;
		pq.push(data[i].S);
		while(pq.size()>sz) v.pb(pq.top()),pq.pop();
	}
	sort(ALL(v),greater<int>()),sz=0;
	for(int i=0,nw=b-1;i<v.size();++i)
	{
		while(nw>=0&&y[nw]>v[i])
			--nw,sz+=c;
		if(i>=sz) return 0;
	}
	return 1;
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) 
{
	n=T,a=A,b=B;
    int l=1,r=T+1;
    for(int i=0;i<T;++i)
    	data[i]=MP(W[i],S[i]);
    for(int i=0;i<A;++i)
    	x[i]=X[i];
    for(int i=0;i<B;++i)
    	y[i]=Y[i];
    sort(data,data+T,greater<pii>()),sort(x,x+a),sort(y,y+b);
    while(l<r)
    {
    	int m=l+r>>1;
    	if(check(m)) r=m;
    	else l=m+1;
    }
    if(l==T+1) return -1;
    return l;
}

Compilation message (stderr)

robots.cpp: In function 'bool check(int)':
robots.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(pq.size()>sz) v.pb(pq.top()),pq.pop();
         ~~~~~~~~~^~~
robots.cpp:34:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0,nw=b-1;i<v.size();++i)
                     ~^~~~~~~~~
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:56:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
      int m=l+r>>1;
            ~^~
#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...