QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#776696#7781. Sheep Eat Wolvesucup-team1412WA 1ms3696kbC++233.8kb2024-11-23 20:17:522024-11-23 20:17:52

Judging History

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

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

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;

        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 || (!ok1 && !ok2)) cout << -1;
    else cout << min(cnt1, cnt2);
    return 0;
}

详细

Test #1:

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

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3696kb

input:

2 5 1 1

output:

0

result:

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