QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#1503 | #590720 | #7781. Sheep Eat Wolves | CCF | texiw | Success! | 2025-02-04 10:03:58 | 2025-02-04 10:04:00 |
详细
Extra Test:
Wrong Answer
time: 0ms
memory: 3584kb
input:
87 81 1 48
output:
203
result:
wrong answer 1st numbers differ - expected: '237', found: '203'
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#590720 | #7781. Sheep Eat Wolves | texiw | WA | 1ms | 3712kb | C++20 | 3.2kb | 2024-09-26 10:29:58 | 2025-02-04 10:19:52 |
answer
// #pragma GCC optimize(2)
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned int;
signed main() {
std::cin.tie(0)->sync_with_stdio(0);
int x, y, p, q; std::cin >> x >> y >> p >> q;
int x2{}, y2{};
int ox = x, oy = y;
bool flag = 0;
int s;
int cnt{};
int tle = 0;
if (y - x > q) {
goto S1;
}
// ?????????, ?????, ???????????
x -= p;
x2 += p;
cnt += 2;
if (x <= 0) {
std::cout << 1 << "\n";
return 0;
}
S1:
s = std::min(y, p);
y -= s;
y2 += s;
cnt += 2;
if (y - x == q) {
s = std::min(y, p);
y -= s;
y2 += s;
cnt += 2;
}
while (1) {
++tle;
if (tle == 200) break;
// std::cout << x << " " << y << " " << x2 << " " << y2 << "\n";
if (!flag) {
++cnt;
int d = (y - x + p - q + 1) / 2;
// std::cout << d << "\n";
// ?????, ???????????
if (p >= x) break;
// ?? p - d < 0 , ??????????, ????
if (p < d) {
std::cout << "-1\n";
return 0;
}
// ????????? p - d ? x ?
// if (p - d >= x) {
// break;
// }
if (d > 0) {
x -= p - d;
y -= d;
x2 += p - d;
y2 += d;
} else {
x -= p;
x2 += p;
}
flag = !flag;
} else {
++cnt;
int d = y2 - x2 - q;
// std::cout << d << "\n";
if (d > p && x2 != 0) {
std::cout << "-1\n";
return 0;
}
if (d > 0 && x2 != 0) {
y2 -= d;
y += d;
}
flag = !flag;
}
}
S2:
x = ox, y = oy, x2 = 0, y2 = 0, flag = 0;
int cnt2{};
while (1) {
// std::cout << x << " " << y << " " << x2 << " " << y2 << "\n";
if (!flag) {
++cnt2;
int d = (y - x + p - q + 1) / 2;
// std::cout << d << "\n";
// ?????, ???????????
if (p >= x) break;
// ?? p - d < 0 , ??????????, ????
if (p < d) {
std::cout << "-1\n";
return 0;
}
// ????????? p - d ? x ?
// if (p - d >= x) {
// break;
// }
if (d > 0) {
x -= p - d;
y -= d;
x2 += p - d;
y2 += d;
} else {
x -= p;
x2 += p;
}
flag = !flag;
} else {
++cnt2;
int d = y2 - x2 - q;
// std::cout << d << "\n";
if (d > p && x2 != 0) {
std::cout << "-1\n";
return 0;
}
if (d > 0 && x2 != 0) {
y2 -= d;
y += d;
}
flag = !flag;
}
}
// std::cout << cnt << " " << cnt2 << "\n";
std::cout << std::min(cnt, cnt2) << "\n";
}