왜 정답 비율이 33%인지 잘 모르겠다. 그나마 주의할 것이 있다면 ch배열을 1000001로 해야한다는 것?
#include <iostream>
#include <queue>
using namespace std;
struct Loc {
int x, cnt;
Loc(int a, int b) {
x = a;
cnt = b;
}
};
int ch[1000001];
int main() {
//freopen("in1.txt", "rt", stdin);
int f, s, g, u, d;
cin >> f >> s >> g >> u >> d;
queue<Loc> Q;
int dx[2] = { u,d };
Q.push(Loc(s, 0));
ch[s] = 1;
while (!Q.empty()) {
Loc tmp = Q.front();
Q.pop();
//cout << tmp.x << " " << tmp.cnt << '\n';
if (tmp.x == g) {
cout << tmp.cnt << '\n';
return 0;
}
for (int i = 0; i < 2; i++) {
int xx;
if (i == 0) xx = tmp.x + dx[i];
else if(i==1) xx = tmp.x - dx[i];
if (xx > f || xx <= 0) continue;
if (ch[xx] == 0) {
ch[xx] = 1;
Q.push(Loc(xx, tmp.cnt + 1));
}
}
}
cout << "use the stairs" << '\n';
return 0;
}