이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
using ll = long long;
const int MAX = 2000;
map<pair<int, int>, int> dis;
vector<int> types[MAX];
struct Etat
{
int pos, last_type;
int get() const
{
return dis[{pos, last_type}];
}
};
int main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int nb_doge, len_route;
cin >> len_route >> nb_doge;
vector<pair<int, int> > doge(nb_doge);
for (auto &[building, skip] : doge)
{
cin >> building >> skip;
types[building].push_back(skip);
}
int target = doge[1].first;
queue<Etat> pq;
dis[{doge[0].first, doge[0].second}] = 0;
pq.push({doge[0].first, doge[0].second});
while (SZ(pq))
{
Etat cur = pq.front(); pq.pop();
auto [pos, last_type] = cur;
if (pos == target)
{
cout << cur.get() << endl;
return 0;
}
types[pos].push_back(last_type);
for (auto type : types[pos])
{
if (pos >= type and !dis.count({pos-type, type}))
{
dis[{pos - type, type}] = 1 + cur.get();
pq.push({pos - type, type});
}
if (pos + type < len_route and !dis.count({pos+type, type}))
{
dis[{pos+type, type}] = 1 + cur.get();
pq.push({pos+type, type});
}
}
types[pos].pop_back();
}
cout << -1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |