This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m, n;
ll b[30030], p[30030];
vector<ll>srapers[30030];
vector<pair<ll, ll> >graff[30030];
ll dist[30030];
bool check1[30030];
ll INF=LONG_LONG_MAX;
/*void dijkstra(ll cvor)
{
for(int i=0; i<30030; i++){check1[i]=false; dist[i]=INF;}
priority_queue<pair<ll, ll> >ord;
dist[cvor]=0;
ord.push({0, cvor});
while(!ord.empty())
{
int cv=ord.top().second;
ord.pop();
if(check1[cv])continue;
check1[cv]=true;
for(int j=0; j<graff[cv].size(); j++)
{
ll pp=graff[cv][j].first;
dist[pp]=min(dist[pp], dist[cv]+graff[cv][j].second);
if(!check1[pp])ord.push({-dist[pp], pp});
}
}
}*/
void dijkstra(int s, vector<int> & p) {
p.assign(n, -1);
vector<bool> u(n, false);
for(int i=0; i<n; i++)dist[i]=INF;
dist[s] = 0;
for (int i = 0; i < n; i++) {
int v = -1;
for (int j = 0; j < n; j++) {
if (!u[j] && (v == -1 || dist[j] < dist[v]))
v = j;
}
if (dist[v] == INF)
break;
u[v] = true;
for (auto edge : graff[v]) {
int to = edge.first;
int len = edge.second;
if (dist[v] + len < dist[to]) {
dist[to] = dist[v] + len;
p[to] = v;
}
}
}
}
int main()
{
cin>>n>>m;
for(int i=0; i<m; i++)
{
cin>>b[i]>>p[i];
srapers[b[i]].push_back(i);
}
for(int i=0; i<m; i++)
{
ll br=0;
while(b[i]-br*p[i]>=0 or b[i]+br*p[i]<n)
{
int j;
if(b[i]-br*p[i]>=0)
{
j=b[i]-br*p[i];
for(int l=0; l<srapers[j].size(); l++)
{
graff[i].push_back({srapers[j][l], br});
}
}
if(b[i]+br*p[i]<n)
{
j=b[i]+br*p[i];
for(int l=0; l<srapers[j].size(); l++)
{
graff[i].push_back({srapers[j][l], br});
}
}
br++;
}
}
vector<int>p(30030);
dijkstra(0, p);
if(dist[1]==INF){cout<<-1; return 0;}
cout<<dist[1];
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:80:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int l=0; l<srapers[j].size(); l++)
| ~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:88:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int l=0; l<srapers[j].size(); l++)
| ~^~~~~~~~~~~~~~~~~~
# | 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... |