이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 3e4 + 10 , maxq =3e6 + 1e5 , sq = 100 ,mod = 1e9 + 7 , inf = 1e9 + 7, lg = 21 ;
int r[maxn][sq + 1] , dis[maxq] , mark[maxq] , x[maxn] , p[maxn] ;vector <int> vec[maxn];
vector <pii> G[maxq] ;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) ;
int n , m ;cin >> n >> m ;
int cnt = n+1 ;
for(int i = 0 ; i < n ; i++){
for(int j=1;j<=sq ; j++){
G[cnt].pb({i ,0});
r[i][j] = cnt ;
if(i >= j){
G[cnt].pb({r[i-j][j] , 1});
G[r[i-j][j]].pb({cnt,1});
}
cnt++;
}
}
int x0 , x1 ;
for(int i = 0 ; i < m ; i++){
cin >> x[i]>> p[i];
if(i==0)x0 = x[i] ;
if(i == 1)x1 =x[i] ;
if(p[i] == 0)continue ;
if(p[i] > sq){
vec[x[i]].pb(p[i]);
}else{
G[x[i]].pb({r[x[i]][p[i]] , 0});
}
}
queue <int> q ;
for(int i = 0; i < cnt ; i++){mark[i] = 0 ;dis[i] = inf ;}
dis[x0]= 0;
q.push(x0) ;
while(q.size()){
int v = q.front() ;q.pop() ;
if(v < n){
for(int z = 0 ; z < vec[v].size() ; z++){
int u = vec[v][z] ;
for(int j = v%u ; j < n ; j+=u){
if(dis[j] > dis[v]+abs(v-j)/u){
dis[j] = dis[v]+abs(v-j)/u ;
q.push(j) ;
}
}
}
}
mark[v] = 1;
for(pii u : G[v]){
if(dis[u.F] > dis[v]+u.S){
dis[u.F] = dis[v] + u.S ;
q.push(u.F) ;
}
}
}
if(dis[x1] == inf){
cout << "-1\n";
}else{
cout << dis[x1] << "\n";
}
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int z = 0 ; z < vec[v].size() ; z++){
| ~~^~~~~~~~~~~~~~~
skyscraper.cpp:69:11: warning: 'x1' may be used uninitialized in this function [-Wmaybe-uninitialized]
69 | if(dis[x1] == inf){
| ~~~~~~^
# | 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... |