Skip to content

Commit dd7d25d

Browse files
authored
Merge pull request #174 from AlgorithmWithGod/khj20006
[20250225] BOJ / S1 / 돌다리 / 권혁
2 parents 8f80c37 + 47de79c commit dd7d25d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
```cpp
2+
3+
#include <iostream>
4+
#include <queue>
5+
#include <bitset>
6+
using namespace std;
7+
8+
int main()
9+
{
10+
cin.tie(0)->sync_with_stdio(0);
11+
12+
int A, B, N, M;
13+
cin >> A >> B >> N >> M;
14+
bitset<100001> v;
15+
queue<pair<int, int>> Q;
16+
Q.emplace(N, 0);
17+
v[N] = 1;
18+
19+
int d[6] = { 1,-1,A,-A,B,-B };
20+
while (!Q.empty()) {
21+
auto[n, t] = Q.front();
22+
Q.pop();
23+
if (n == M) return cout << t, 0;
24+
for (int i = 0; i < 6; i++) {
25+
int x = n + d[i];
26+
if (x < 0 || x > 100000 || v[x]) continue;
27+
v[x] = 1;
28+
Q.emplace(x, t + 1);
29+
}
30+
if (n*A <= 100000 && !v[n*A]) { v[n*A] = 1; Q.emplace(n*A, t + 1); }
31+
if (n*B <= 100000 && !v[n*B]) { v[n*B] = 1; Q.emplace(n*B, t + 1); }
32+
}
33+
34+
35+
}
36+
37+
```

0 commit comments

Comments
 (0)