이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
vector<ii> al[6*1000000];
int dis[6000000];
set<ii> s;
int dij(int so,int t)
{
for(int i=0;i<6000000;++i)
dis[i]=1000000000;
s.insert(mp(0,so));
while(s.size()!=0)
{
ii v=(*s.begin());
s.erase(s.begin());
dis[v.S]=v.F;
for(int i=0;i<al[v.S].size();++i)
{
if(al[v.S][i].S+v.F<dis[al[v.S][i].F])
{
s.erase(mp(dis[al[v.S][i].F],al[v.S][i].F));
dis[al[v.S][i].F]=al[v.S][i].S+v.F;
s.insert(mp(dis[al[v.S][i].F],al[v.S][i].F));
}
}
}
if(dis[t]==1000000000)
return(-1);
return(dis[t]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli test=1;
for(;test>0;--test)
{
int n,m,rn;
cin>>n>>m;
rn=sqrt(n)+1;
ii dg[m];
for(int i=1;i<rn;++i)
{
for(int j=0;j<n;++j)
{
if(j+i<n)
{
al[i*n+j].pb(mp(i*n+j+i,1));
al[i*n+j+i].pb(mp(i*n+j,1));
}
if(j+i<n)
al[i*n+j].pb(mp(rn*n+j+i,1));
if(j-i>=0)
al[i*n+j].pb(mp(rn*n+j-i,1));
}
}
for(int i=0;i<m;++i)
{
int f,s;
cin>>f>>s;
dg[i]=mp(f,s);
if(s<rn)
al[rn*n+f].pb(mp((s)*n+f,0));
else
{
int p=f+s;
while(p<n)
{
al[rn*n+f].pb(mp(rn*n+p,(p-f)/s));
p+=s;
}
p=f-s;
while(p>=0)
{
al[rn*n+f].pb(mp(rn*n+p,(f-p)/s));
p-=s;
}
}
}
cout<<dij(dg[0].S*n+dg[0].F,dg[1].S*n+dg[1].F)<<endl;
}
return(0);
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int dij(int, int)':
skyscraper.cpp:30:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[v.S].size();++i)
~^~~~~~~~~~~~~~~
# | 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... |