QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660506#7781. Sheep Eat WolvesoumashuWA 0ms3660kbC++171.5kb2024-10-20 11:43:342024-10-20 11:43:35

Judging History

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

  • [2024-10-20 11:43:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-10-20 11:43:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,p,q,m=0,n=0,sum=0;
    cin>>x>>y>>p>>q;
    if(p!=1){
        while(1){
            int ans=y-x-q;
            //cout<<ans<<"\n";
            if(p>=x){ sum++; break; }
            if(p<ans){ cout<<-1; return 0; }
            if(ans>0){
                y-=ans;
                x-=(p-ans)/2;
                y-=(p-ans)/2;
                m+=(p-ans)/2;
                n+=ans+(p-ans)/2;
                sum++;
            }
            else if(ans<0){
                x+=ans;
                x-=(p+ans)/2;
                y-=(p+ans)/2;
                m+=(p+ans)/2-ans;
                n+=(p+ans)/2;
                sum++;
            }
            else if(ans==0){
                x-=p/2;
                y-=p/2;
                m+=p/2;
                n+=p/2;
                sum++;
            }
            //cout<<n<<"\n";
            int ans2=n-m-q;
            if(p<ans2){
                cout<<-1;
                return 0;
            }
            if(ans2>0&&m!=0){
                n-=ans2;
                y+=ans2;
                
            }
            sum++;
            //cout<<x<<" "<<y<<" "<<m<<" "<<n<<"\n";
            if(x<=0)break;
        }
    }
    else {
            int ans=y-x-q;
            if(ans>p){
                cout<<"-1";
                return 0;
            }
            sum+=2*(x+q-y);
            x=y-q;
            sum+=(x-1)*4+1;
    }
    cout<<sum;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3644kb

input:

10 9 1 10

output:

15

result:

wrong answer 1st numbers differ - expected: '19', found: '15'