이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
#define int long long
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
vector <int> g[n];
int st, en;
for ( int i = 1; i <= m; i++ ){
int x, y; cin >> x >> y;
g[x].pb(y);
if ( i == 1 ) st = x;
if ( i == 2 ) en = x;
}
const int inf = 1e15 + 1, N = 2e3 + 1;
vector <vector<int>> dis(n, vector <int> (N, inf));
deque <pair<int,int>> dq;
for ( auto i: g[st] ){
dq.pb({st, i});
dis[0][i] = 0;
}
while ( !dq.empty() ){
auto [x, p] = dq.front();
dq.pop_front();
int v = dis[x][p];
if ( x - p >= 0 and chmin(dis[x - p][p], v + 1) ){
dq.pb({x - p, p});
}
if ( x + p < n and chmin(dis[x + p][p], v + 1) ){
dq.pb({x + p, p});
}
for ( auto to: g[x] ){
if ( chmin(dis[x][to], v) ){
dq.push_front({x, to});
}
}
}
int ans = *min_element(all(dis[en]));
if ( ans == inf ) ans = -1;
cout << ans;
cout << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:34:9: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
34 | int st, en;
| ^~
skyscraper.cpp:64:38: warning: 'en' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | int ans = *min_element(all(dis[en]));
| ^
# | 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... |