이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7; //
struct node{
int a, b, dis;
};
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
queue<node> q;
vector<int> pos[n];
int d[m], x[m];
for (int i = 0; i < m; i++){
int x[i];
cin >> x[i] >> d[i];
pos[x[i]].push_back(i);
}
bitset<1000> vis[m]{};
int ans = inf;
q.push({0, x[0], 0});
vis[0][x[0]] = true;
while(!q.empty()){
node u = q.front();
q.pop();
//cout << u.a << ' ' << u.b << ' ' << u.dis << '\n';
if (u.b + d[u.a] < n and !vis[u.a][u.b + d[u.a]]){
q.push({u.a, u.b + d[u.a], u.dis + 1});
vis[u.a][u.b + d[u.a]] = true;
}
if (u.b - d[u.a] >= 0 and !vis[u.a][u.b - d[u.a]]){
q.push({u.a, u.b - d[u.a], u.dis + 1});
vis[u.a][u.b - d[u.a]] = true;
}
while (!pos[u.b].empty()){
int v = pos[u.b].back();
pos[u.b].pop_back();
if (!vis[v][u.b]){
q.push({v, u.b, u.dis});
vis[v][u.b] = true;
}
}
if (u.a == 1) ans = min(ans, u.dis);
}
cout << ans;
}
# | 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... |