QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735521#7781. Sheep Eat WolvesSuhy#TL 0ms1632kbC++17969b2024-11-11 20:30:072024-11-11 20:30:09

Judging History

你现在查看的是最新测评结果

  • [2024-11-11 20:30:09]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:1632kb
  • [2024-11-11 20:30:07]
  • 提交

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

output:


result: