QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764371#7781. Sheep Eat WolvesfosovWA 0ms3724kbC++141.4kb2024-11-20 08:52:062024-11-20 08:52:13

Judging History

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

  • [2024-11-20 08:52:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3724kb
  • [2024-11-20 08:52:06]
  • 提交

answer

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

#define ll long long 
#define lll __int128
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353
#define pii pair<int, int>
#define ld long double
#define fi first
#define se second
#define all(a) a.begin(), a.end()

#define N 110


int main() {
#ifdef TEST
    freopen("zz.in", "r+", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int x, y, p, q; cin >> x >> y >> p >> q;    
    int sx = 0, sy = 0;
    y -= sy;

    int tx = 0, ty = 0;
    int d = INF, stp = 0, f = 1;

    auto trans = [&](int& x, int& y, int d) {
        x += d, y -= d;
    };

    while (stp < 10) {
        f &= p-sx-sy>=y-(x+q);
        trans(sy, y, max(0, y-(x+q)));
        
        trans(sx, x, min(p-sx-sy, max(0, x-(y-q))));
        
        if ((p-sx-sy)%2==1 && y) trans(sy, y, 1);
        d = min((p-sx-sy)/2, min(x, y));
        trans(sx, x, d);
        trans(sy, y, d);

        if (p-sx>=x) {
            trans(y, sy, sy);
            trans(sx, x, x);
        }
        ++ stp;

        trans(tx, sx, sx);
        trans(ty, sy, sy);
        if (x == 0) break;

        if (tx) {
            f &= p-sx-sy>=ty-(tx+q);
            trans(sy, ty, max(0, ty-(tx+q)));
        }
        ++ stp;

    }

    cout << (!f || stp == int(1e5) ? -1 : stp) << '\n';
}   

// 3 3
// 2 2

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

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

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

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

input:

10 9 1 10

output:

10

result:

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