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;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=3e4+5;
int n, m, pos0, pos1;
vector <pii> ls[N];
set <int> S[N];
set <pii> s;
int dist[N];
int dodaj(int a, int b, int c) {
// printf("%d -> %d == %d\n", a, b, c);
ls[a].pb(mp(b, c));
// ls[b].pb(mp(a, c));
}
void dijkstra(int poc) {
memset(dist, INF, sizeof dist);
dist[poc]=0;
s.insert(mp(0, poc));
while (!s.empty()) {
pii node=*s.begin();
s.erase(s.begin());
for (pii sus:ls[node.Y]) {
if (sus.Y+node.X>=dist[sus.X]) continue;
if (s.count(mp(dist[sus.X], sus.X))) s.erase(mp(dist[sus.X], sus.X));
dist[sus.X]=sus.Y+node.X;
s.insert(mp(dist[sus.X], sus.X));
}
}
}
void solve() {
for (int i=0; i<n; ++i) {
for (int x:S[i]) {
for (int j=i+x; j<n; j+=x) {
dodaj(i, j, (j-i)/x);
if (S[j].count(x)) break;
}
for (int j=i-x; j>=0; j-=x) {
dodaj(i, j, (i-j)/x);
if (S[j].count(x)) break;
}
}
}
printf("0\n");
exit(0);
dijkstra(pos0);
printf("%d\n", dist[pos1]==INF ? -1 : dist[pos1]);
}
void load() {
scanf("%d %d", &n, &m);
for (int i=0; i<m; ++i) {
int a, b;
scanf("%d %d", &a, &b);
if (i==0) pos0=a;
if (i==1) pos1=a;
S[a].insert(b);
}
}
int main() {
load();
solve();
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'int dodaj(int, int, int)':
skyscraper.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
28 | }
| ^
skyscraper.cpp: In function 'void load()':
skyscraper.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
66 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
69 | scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# | 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... |