QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#776761#7781. Sheep Eat Wolvesucup-team1412WA 1ms3636kbC++234.2kb2024-11-23 20:52:412024-11-23 20:52:41

Judging History

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

  • [2024-11-23 20:52:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3636kb
  • [2024-11-23 20:52:41]
  • 提交

answer

#include <iostream>
using namespace std;
typedef long long ll;
#define endl '\n'
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x, y, p, q;
    cin >> x >> y >> p >> q;
    ll ls = x, lw = y, rw = 0, rs = 0, ow = 0, os = 0;
    ll loc = 0;
    bool ok1 = true;
    ll cnt1 = 0;
    while (rs < x) {
        ll onship = 0;
        if (cnt1 > 5000) {
            break;
        }
        if (loc == 0) {
            if (ls <= p) {
                cnt1++;
                break;
            }
            while (lw > ls + q) {
                lw--;
                onship++;
                ow++;
                if (onship > p) {
                    ok1 = false;
                    break;
                }
            }
            if (!ok1) break;
            while (ls + q > lw && onship < p) {
                ls--;
                os++;
                onship++;
            }
            while (onship < p) {
                lw--;
                onship++;
                ow++;
                if (onship < p) {
                    ls--;
                    onship++;
                    os++;
                }
            }
            rw += ow;
            rs += os;
            ow = 0;
            os = 0;
            onship = 0;
            cnt1++;
            loc = 1;
        }
        else {
            while (rw > rs + q && rs != 0) {
                ow++;
                rw--;
                onship++;
                if (onship > p) {
                    ok1 = false;
                    break;
                }
            }
            if (!ok1) break;
            lw += ow;
            ow = 0;
            onship = 0;
            cnt1++;
            loc = 0;
        }
    }
    ls = x, lw = y, rw = 0, rs = 0, ow = 0, os = 0;
    loc = 0;
    bool ok2 = true;
    ll cnt2 = 0;
    if (ls > p) {

        ls -= p;
        lw -= p;
        rw += p;
        rs += p;
        cnt2 += 4;
        if (lw > ls + q) ok2 = false;
        else {
            while (rs < x) {
                ll onship = 0;
                if (cnt2 > 5000) {
                    break;
                }
                if (loc == 0) {
                    if (ls <= p) {
                        cnt2++;
                        break;
                    }
                    while (lw > ls + q) {
                        lw--;
                        onship++;
                        ow++;
                        if (onship > p) {
                            ok2 = false;
                            break;
                        }
                    }
                    if (!ok2) break;
                    while (ls + q > lw && onship < p) {
                        ls--;
                        os++;
                        onship++;
                    }
                    while (onship < p) {
                        lw--;
                        onship++;
                        ow++;
                        if (onship < p) {
                            ls--;
                            onship++;
                            os++;
                        }
                    }
                    rw += ow;
                    rs += os;
                    ow = 0;
                    os = 0;
                    onship = 0;
                    cnt2++;
                    loc = 2;
                }
                else {
                    while (rw > rs + q && rs != 0) {
                        ow++;
                        rw--;
                        onship++;
                        if (onship > p) {
                            ok2 = false;
                            break;
                        }
                    }
                    if (!ok2) break;
                    lw += ow;
                    ow = 0;
                    onship = 0;
                    cnt2++;
                    loc = 0;
                }
            }


        }
    }

    if (cnt2 > 5000) cout << -1;
    else if (ok1 && ok2) {
        cout << min(cnt1, cnt2);
    }
    else if (ok1) cout << cnt1;
    else if (ok2) cout << cnt2;
    else cout << -1;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1 1 1 0

output:

0

result:

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