이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 30005;
const int MAXP = 2005;
const int MAXM = 30005;
const int LIM = 800;
int n,m;
int a[MAXM],p[MAXM];
vi v[MAXN];
ll dist[MAXN][LIM];
priority_queue<iii,vector<iii>,greater<iii>> q;
void add(ll x, ll y, ll w, ll d)
{
if(x<0 || x>=n) return;
if(dist[x][y]>d+w){
dist[x][y]=d+w;
q.push({dist[x][y],{x,y}});
}
}
void dijkstra(ii src)
{
dist[src.F][src.S]=0;
q.push({0,src});
while(!q.empty())
{
ii u=q.top().S; q.pop();
if(u.S)
{
if(u.S>=LIM){
for(int i=u.F%u.S;i<n;i+=u.S){
add(i, 0, abs(i-u.F)/u.S, dist[u.F][u.S]);
}
}
else{
add(u.F-u.S, u.S, 1, dist[u.F][u.S]);
add(u.F+u.S, u.S, 1, dist[u.F][u.S]);
add(u.F, 0, 0, dist[u.F][u.S]);
}
}
else
{
for(int P: v[u.F])
{
add(u.F, P, 0, dist[u.F][u.S]);
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
forn(i,0,m){
cin>>a[i]>>p[i];
v[a[i]].pb(p[i]);
}
forn(i,0,n) forn(j,0,MAXP) dist[i][j]=INF;
dijkstra({a[0],0});
if(dist[a[1]][0]<INF) cout<<dist[a[1]][0]<<'\n';
else cout<<-1<<'\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:94:39: warning: iteration 800 invokes undefined behavior [-Waggressive-loop-optimizations]
forn(i,0,n) forn(j,0,MAXP) dist[i][j]=INF;
~~~~~~~~~~^~~~
skyscraper.cpp:10:36: note: within this loop
#define forn(i,a,b) for(int i=(a);i<(b);i++)
^
skyscraper.cpp:94:14: note: in expansion of macro 'forn'
forn(i,0,n) forn(j,0,MAXP) dist[i][j]=INF;
^~~~
skyscraper.cpp: In function 'void dijkstra(ii)':
skyscraper.cpp:65:9: warning: array subscript is above array bounds [-Warray-bounds]
add(i, 0, abs(i-u.F)/u.S, dist[u.F][u.S]);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |