QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633271#7781. Sheep Eat Wolvesthe_fool#TL 0ms3656kbC++201.2kb2024-10-12 14:56:582024-10-12 14:56:59

Judging History

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

  • [2024-10-12 14:56:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3656kb
  • [2024-10-12 14:56:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using LL = long long;
using ll = long long;

int x,y,p,q;
void solve() {
    cin>>x>>y>>p>>q;
    int x1=0,y1=0,ans=0;
    while(x)
    {
        ans++;
        if(y1-x1>q&&x1)
        {
            ans=-1;
            break;
        }
        if(x<=p)break;
        if(y-x>q&&ans!=1)
        {
            ans=-1;
            break;
        }


        int t=x+q-y,t1=0;
        if(t>=0)
        {
            if(t>=p)t=p;
            else t1=(p-t)/2;
            x-=t+t1;
            y-=t1;
            x1+=t+t1;
            y1+=t1;
            if(x<=p)y1-=p;
        }
        else
        {
            t=-t;
            if(t>=p)t=p;
            else t1=(p-t)/2;
            x-=t1;
            y-=t+t1;
            x1+=t1;
            y1+=t+t1;
            if(x<=p)y1-=p;
        }
    }
    if(ans==-1)cout<<ans<<endl;
    else cout<<ans+ans-1<<endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

#ifdef Debug
    assert(freopen("in.txt", "r", stdin));
    assert(freopen("out.txt", "w", stdout));
#endif

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

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: