#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
#define mp make_pair
ll attack, strength[2], heal[2], res;
map < pair <ll, ll>, ll > d;
queue <ll> Qx, Qy, Qr;
int main() {
scanf("%lld%lld%lld%lld%lld",&attack,&strength[0],&strength[1],&heal[0],&heal[1]);
if (strength[0] < strength[1] || (strength[0] == strength[1] && heal[0] < heal[1])) swap(strength[0], strength[1]), swap(heal[0], heal[1]);
while (strength[0] > attack*2) strength[0] -= attack*2, strength[0] += heal[0], res++;
d[mp(strength[0], strength[1])] = res;
Qx.push(strength[0]);
Qy.push(strength[1]);
Qr.push(res);
ll x, y, r, a, b;
while (!Qx.empty()) {
x = Qx.front(); Qx.pop();
y = Qy.front(); Qy.pop();
r = Qr.front(); Qr.pop();
if (x == 0 && y == 0) break;
a = x-2*attack;
if (a <= 0) a = 0;
else a += heal[0];
if (d[mp(a,y)] == 0) {
d[mp(a,y)] = r+1;
Qx.push(a); Qy.push(y); Qr.push(r+1);
}
b = y-2*attack;
if (b <= 0) b = 0;
else b += heal[1];
if (d[mp(x,b)] == 0) {
d[mp(x,b)] = r+1;
Qx.push(x); Qy.push(b); Qr.push(r+1);
}
a = x-attack;
if (a <= 0) a = 0;
else a += heal[0];
b = y-attack;
if (b <= 0) b = 0;
else b += heal[1];
if (d[mp(a,b)] == 0) {
d[mp(a,b)] = r+1;
Qx.push(a); Qy.push(b); Qr.push(r+1);
}
}
printf("%lld",d[mp(0,0)]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Memory limit exceeded |
272 ms |
32768 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Memory limit exceeded |
480 ms |
32768 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Memory limit exceeded |
388 ms |
32768 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
500 ms |
32768 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |