이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=3e4+5;
const ll inf=2e18;
int n,m,b[maxN+1],p[maxN+1];
namespace sub4
{
const int LIMIT=2e3+5;
int d[LIMIT+1][LIMIT+1];
struct node
{
int u,power;
};
deque<node> q;
void solve()
{
for(int i=0;i<LIMIT;i++)
{
for(int j=0;j<LIMIT;j++)
{
d[i][j]=inf;
}
}
q.push_front({b[0],p[0]});
d[b[0]][p[0]]=0;
while(!q.empty())
{
node tmp=q.front();
q.pop_front();
int u=tmp.u,power=tmp.power;
//cout<<u<<" "<<power<<'\n';
if(u==b[1])
{
cout<<d[u][power];
return;
}
if(u+power<n)
{
if(d[u+power][power]>d[u][power]+1)
{
d[u+power][power]=d[u][power]+1;
q.push_back({u+power,power});
}
}
if(u-power>=0)
{
if(d[u-power][power]>d[u][power]+1)
{
d[u-power][power]=d[u][power]+1;
q.push_back({u-power,power});
}
}
for(int i=0;i<m;i++)
{
if(b[i]==u)
{
if(d[u][p[i]]>d[u][power])
{
d[u][p[i]]=d[u][power];
q.push_front({u,p[i]});
}
}
}
}
cout<<-1;
}
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>b[i]>>p[i];
}
sub4::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'void sub4::solve()':
skyscraper.cpp:25:25: warning: overflow in conversion from 'long long int' to 'int' changes value from '2000000000000000000' to '1321730048' [-Woverflow]
25 | d[i][j]=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... |