이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "robots.h"
#define inf 1000000007
#define mod 1000000007
#define rnd() rand_num()
#define bigrnd() dis(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#define int long long
using namespace std;
unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0,inf);
template <typename T> void read(T &x){
x=0;char ch=getchar();int fh=1;
while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
x*=fh;
}
template <typename T> void write(T x) {
if (x<0) x=-x,putchar('-');
if (x>9) write(x/10);
putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
int m1,m2,n;
int lim1[50005],lim2[50005];
pair<int,int> p[1000005];
bool check(int mid)
{
priority_queue<int> pq;
int id=1;
for(int i=1;i<=m1;++i)
{
while(id<=n&&p[id].first<lim1[i])
{
pq.push(p[id].second);
id++;
}
for(int j=1;j<=mid;++j)
{
if(pq.empty()) break;
pq.pop();
}
}
while(id<=n)
{
pq.push(p[id].second);
id++;
}
for(int i=m2;i>=1;--i)
{
for(int j=1;j<=mid;++j)
{
if(pq.empty()) break;
if(pq.top()>=lim2[i]) break;
pq.pop();
}
}
return pq.empty();
}
int putaway(int A,int B,int T,int X[],int Y[],int W[],int S[])
{
m1=A;m2=B;n=T;
for(int i=1;i<=m1;++i)
lim1[i]=X[i-1];
for(int i=1;i<=m2;++i)
lim2[i]=Y[i-1];
sort(lim1+1,lim1+m1+1);
sort(lim2+1,lim2+m2+1);
for(int i=1;i<=n;++i)
p[i]=make_pair(W[i-1],S[i-1]);
sort(p+1,p+n+1);
int l=1,r=T;
while(l<r)
{
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
if(check(l)) return l;
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:80:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
80 | int mid=l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |