QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755421 | #7781. Sheep Eat Wolves | Star_s# | WA | 0ms | 3708kb | C++14 | 990b | 2024-11-16 17:18:03 | 2024-11-16 17:18:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
int sheep_lef, wolf_lef, sheep_rig = 0, wolf_rig = 0, n, k;
cin >> sheep_lef >> wolf_lef >> n >> k;
int cnt = 0, all = sheep_lef;
while (true) {
int i;
if (sheep_rig == all) {
cout << cnt << endl;
break;
}
for (i = min(sheep_lef, n); i >= 0; i--) {
int a = sheep_lef - i, b = wolf_lef - (n - i);
if (b != 0 && a != 0 && b - a > k) {
continue;
}
else {
sheep_lef = a, wolf_lef = b, sheep_rig += i, wolf_rig += (n - i);
break;
}
}
if (i == -1) {
cout << -1 << endl;
break;
}
cnt++;
if (sheep_rig == all) {
cout << cnt << endl;
break;
}
for (i = 0; i <= wolf_rig; i++) {
int b = wolf_rig - i;
if (sheep_rig != 0 && b != 0 && b - sheep_rig > k) {
continue;
}
else {
wolf_rig = b;
wolf_lef += i;
break;
}
}
if (i > wolf_rig)
{
cout << -1 << endl;
break;
}
cnt++;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3708kb
input:
3 5 2 0
output:
-1
result:
wrong answer 1st numbers differ - expected: '5', found: '-1'