이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const int mxN = 3e4 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
int n, m, pos[mxN], dist[mxN], len[mxN]; vi nodes[mxN]; bool done[mxN];
priority_queue<pii, vpii, greater<pii>> pq;
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
memset(len, 0x3f, sizeof(len));
F0R(i, m){
cin >> pos[i] >> dist[i];
nodes[pos[i]].pb(dist[i]);
}
int F = pos[0], S = pos[1];
len[pos[0]] = 0;
pq.push({0, pos[0]});
while(!pq.empty()){
pii x = pq.top(); pq.pop();
// cout << x.f << " " << x.s << endl;
if(x.f!=len[x.s]) continue;
trav(speed, nodes[x.s]){
int p = x.s + speed;
for(int i = 1; p < n; i++, p+=speed){
if(ckmin(len[p], x.f+i)){
pq.push({len[p], p});
}
}
p = x.s - speed;
for(int i = 1; p >= 0; i++, p-=speed){
if(ckmin(len[p], x.f+i)){
pq.push({len[p], p});
}
}
}
}
cout << (len[S]>=MOD?-1:len[S]) << nl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:42:9: warning: unused variable 'F' [-Wunused-variable]
42 | int F = pos[0], S = pos[1];
| ^
# | 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... |