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 b[30030], p[30030];
vector<int>srapers[30030];
vector<pair<int, int> >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});
}
}
}
int main()
{
ll m, n;
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++)
{
int br=1;
bool ch=false;
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});
//graff[srapers[j][l]].push_back({i, 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});
//graff[srapers[j][l]].push_back({i, br});
}}
br++;
}
}
/*/ for(int i=0; i<m; i++)
{
cout<<i<<endl;
for(int j=0; j<graff[i].size(); j++)
{
cout<<graff[i][j].first<<" "<<graff[i][j].second<<endl;
}
cout<<endl;
}*/
dijkstra(0);
cout<<dist[1];
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'void dijkstra(ll)':
skyscraper.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int j=0; j<graff[cv].size(); j++)
| ~^~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int l=0; l<srapers[j].size(); l++)
| ~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int l=0; l<srapers[j].size(); l++)
| ~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:45:14: warning: unused variable 'ch' [-Wunused-variable]
45 | bool ch=false;
| ^~
# | 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... |