System Testing
143 / 143
AC
143/143 test cases passed
Submission #29
| Problem | SilverDistance |
|---|---|
| Handle | Nur Ahmad Khatim |
| Submitted | 2026-07-28 03:44:22 |
Source Code
using namespace std;
class SilverDistance {
public:
int minSteps(int sx, int sy, int gx, int gy) {
int dx = gx - sx;
int dy = gy - sy;
int count = 0;
count += min(abs(dx), abs(dy));
dx = dx >= 0 ? dx - count : dx + count;
dy = dy >= 0 ? dy - count : dy + count;
if (dy == 0) {
count += abs(dx) % 2 == 0 ? abs(dx) : abs(dx) + 1;
} else if (dx == 0 && dy >= 0) {
count += abs(dy);
} else if (dx == 0 && dy < 0) {
count += abs(dy) % 2 == 0 ? abs(dy) : abs(dy) + 2;
}
return count;
}
};