QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735521 | #7781. Sheep Eat Wolves | Suhy# | TL | 0ms | 1632kb | C++17 | 969b | 2024-11-11 20:30:07 | 2024-11-11 20:30:09 |
Judging History
answer
#include<cstdio>
int x,y,p,q;//sheep,wolf,seat,,safe right
int gans(){
y-=q;
if(y<=0)return 2*((x+p-1)/p)-1;
if(x<=p)return 1;
if(x-p+y-p<=p)return 3;
if(y-p<=x&&(p>>1)+p>=x)return 5;
int P=p;
if(y-q>x)p-=y-q-x,y-=y-q-x;
if(y-p>x)return -1;
if(p<=0)return -1;
int ans=0;
if(x<y){
++ans;
if(y-q==x){
y-=q;
x-=(p-q)>>1;
y-=(p-q)>>1;
q=0;
}else{
int k=y-x;
y-=k;q-=k;
x-=(p-k)>>1;
y-=(p-k)>>1;
if((p-k)&1)--x,--q;
}
}
while(x){
++ans;
if(x<=P)x=0;
else{
x-=p>>1;
y-=p>>1;
if((p&1)){
if(q)--y;
else --x;
}
}
}
return 2*ans-1;
}
int main(){
scanf("%d%d%d%d",&x,&y,&p,&q);
printf("%d",gans());
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1632kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1632kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1620kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 1476kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Time Limit Exceeded
input:
3 3 1 1