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>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#include <stdio.h>
#include <algorithm>
#include <memory.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll const INF = 1e13;
vector<ll> adj[30005];
ll where[30005];
int main()
{
ll n, m, b, p;
input(n); input(m);
vector<ll> adj[n];
ll where[m];
vector<ll> dist(n, INF);
for (ll i=0; i<m; ++i)
{
input(b); input(p);
adj[b].pb(p);
where[i] = b;
}
set<pi> s;
dist[where[0]] = 0;
s.insert(mp(0, where[0]));
while (!s.empty())
{
ll c= s.begin()->s;
s.erase(s.begin());
for (ll u: adj[c])
{
ll jump = 0;
for (ll x=c+u; x<n; x+=u)
{
jump++;
if (dist[x]>dist[c]+jump)
{
if (dist[x]!=INF) s.erase(mp(dist[x], x));
dist[x] = dist[c]+jump;
s.insert(mp(dist[x], x));
}
}
jump = 0;
for (ll x=c-u; x>=0; x-=u)
{
jump++;
if (dist[x]>dist[c]+jump)
{
if (dist[x]!=INF) s.erase(mp(dist[x], x));
dist[x] = dist[c]+jump;
s.insert(mp(dist[x], x));
}
}
}
}
if (dist[where[1]]==INF) {print(-1LL, '\n');}
else {print(dist[where[1]], '\n');}
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
skyscraper.cpp:38:2: note: in expansion of macro 'input'
38 | input(n); input(m);
| ^~~~~
skyscraper.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
skyscraper.cpp:38:12: note: in expansion of macro 'input'
38 | input(n); input(m);
| ^~~~~
skyscraper.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
skyscraper.cpp:44:3: note: in expansion of macro 'input'
44 | input(b); input(p);
| ^~~~~
skyscraper.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
skyscraper.cpp:44:13: note: in expansion of macro 'input'
44 | input(b); input(p);
| ^~~~~
# | 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... |