#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
set<int> S[30001];
VPi v[30001];
bool chk[30001];
int dist[30001];
int B[30001],P[30001];
int n,m;
int main() {
fill(dist,dist+30001,INF);
scanf("%d%d",&n,&m);
fup(i,0,m-1,1)
{
scanf("%d%d",B+i,P+i);
S[B[i]].insert(P[i]);
}
fup(i,0,n-1,1)
{
for(int p:S[i])
{
int d=0,now=i;
while(1)
{
d++,now+=p;
if(now>=n)break;
v[i].pb(mp(now,d));
if(S[now].find(p)!=S[now].end())break;
}
d=0,now=i;
while(1)
{
d++,now-=p;
if(now<0)break;
v[i].pb(mp(now,d));
if(S[now].find(p)!=S[now].end())break;
}
}
}
priority_queue<Pi> q;
int S=B[0],E=B[1];
q.push({0,S});
dist[S] = 0;
while (!q.empty())
{
int x = q.top().second;
q.pop();
if (chk[x])continue;
chk[x] = 1;
for (int i = 0; i < v[x].size(); i++)
{
int next = v[x][i].first;
int cost = v[x][i].second;
if (dist[next] > dist[x] + cost)
{
dist[next] = dist[x] + cost;
q.push({-dist[next], next});
}
}
}
int ans=dist[E];
if(ans==INF)ans=-1;
printf("%d",ans);
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:109:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v[x].size(); i++)
~~^~~~~~~~~~~~~
skyscraper.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",B+i,P+i);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2552 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2552 KB |
Output is correct |
5 |
Correct |
4 ms |
2552 KB |
Output is correct |
6 |
Correct |
4 ms |
2556 KB |
Output is correct |
7 |
Correct |
4 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2552 KB |
Output is correct |
2 |
Correct |
5 ms |
2584 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2552 KB |
Output is correct |
5 |
Correct |
4 ms |
2552 KB |
Output is correct |
6 |
Correct |
4 ms |
2552 KB |
Output is correct |
7 |
Correct |
4 ms |
2552 KB |
Output is correct |
8 |
Correct |
4 ms |
2552 KB |
Output is correct |
9 |
Correct |
4 ms |
2552 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
5 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2552 KB |
Output is correct |
13 |
Correct |
4 ms |
2552 KB |
Output is correct |
14 |
Correct |
5 ms |
2808 KB |
Output is correct |
15 |
Correct |
5 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2552 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2556 KB |
Output is correct |
4 |
Correct |
4 ms |
2552 KB |
Output is correct |
5 |
Correct |
4 ms |
2556 KB |
Output is correct |
6 |
Correct |
4 ms |
2556 KB |
Output is correct |
7 |
Correct |
4 ms |
2580 KB |
Output is correct |
8 |
Correct |
4 ms |
2552 KB |
Output is correct |
9 |
Correct |
4 ms |
2552 KB |
Output is correct |
10 |
Correct |
4 ms |
2552 KB |
Output is correct |
11 |
Correct |
5 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2552 KB |
Output is correct |
13 |
Correct |
4 ms |
2552 KB |
Output is correct |
14 |
Correct |
5 ms |
2680 KB |
Output is correct |
15 |
Correct |
5 ms |
2680 KB |
Output is correct |
16 |
Correct |
5 ms |
2680 KB |
Output is correct |
17 |
Correct |
7 ms |
2936 KB |
Output is correct |
18 |
Correct |
6 ms |
2680 KB |
Output is correct |
19 |
Correct |
6 ms |
2680 KB |
Output is correct |
20 |
Correct |
5 ms |
2684 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2600 KB |
Output is correct |
23 |
Correct |
5 ms |
2680 KB |
Output is correct |
24 |
Correct |
6 ms |
2808 KB |
Output is correct |
25 |
Correct |
6 ms |
2808 KB |
Output is correct |
26 |
Correct |
3 ms |
2808 KB |
Output is correct |
27 |
Correct |
5 ms |
2680 KB |
Output is correct |
28 |
Correct |
6 ms |
2936 KB |
Output is correct |
29 |
Correct |
7 ms |
3320 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
31 |
Correct |
6 ms |
3064 KB |
Output is correct |
32 |
Correct |
5 ms |
2936 KB |
Output is correct |
33 |
Correct |
9 ms |
3960 KB |
Output is correct |
34 |
Correct |
9 ms |
3960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2556 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2552 KB |
Output is correct |
5 |
Correct |
4 ms |
2552 KB |
Output is correct |
6 |
Correct |
4 ms |
2552 KB |
Output is correct |
7 |
Correct |
4 ms |
2552 KB |
Output is correct |
8 |
Correct |
4 ms |
2552 KB |
Output is correct |
9 |
Correct |
4 ms |
2552 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
5 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2552 KB |
Output is correct |
13 |
Correct |
4 ms |
2552 KB |
Output is correct |
14 |
Correct |
5 ms |
2680 KB |
Output is correct |
15 |
Correct |
5 ms |
2852 KB |
Output is correct |
16 |
Correct |
5 ms |
2680 KB |
Output is correct |
17 |
Correct |
6 ms |
2808 KB |
Output is correct |
18 |
Correct |
5 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
5 ms |
2808 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
6 ms |
2684 KB |
Output is correct |
23 |
Correct |
5 ms |
2680 KB |
Output is correct |
24 |
Correct |
6 ms |
2812 KB |
Output is correct |
25 |
Correct |
6 ms |
2808 KB |
Output is correct |
26 |
Correct |
5 ms |
2680 KB |
Output is correct |
27 |
Correct |
5 ms |
2608 KB |
Output is correct |
28 |
Correct |
5 ms |
2936 KB |
Output is correct |
29 |
Correct |
7 ms |
3320 KB |
Output is correct |
30 |
Correct |
5 ms |
2936 KB |
Output is correct |
31 |
Correct |
7 ms |
3064 KB |
Output is correct |
32 |
Correct |
5 ms |
2936 KB |
Output is correct |
33 |
Correct |
10 ms |
3960 KB |
Output is correct |
34 |
Correct |
9 ms |
3964 KB |
Output is correct |
35 |
Correct |
25 ms |
5240 KB |
Output is correct |
36 |
Correct |
8 ms |
3064 KB |
Output is correct |
37 |
Correct |
35 ms |
6008 KB |
Output is correct |
38 |
Correct |
33 ms |
6252 KB |
Output is correct |
39 |
Correct |
33 ms |
6264 KB |
Output is correct |
40 |
Correct |
33 ms |
6348 KB |
Output is correct |
41 |
Correct |
33 ms |
6228 KB |
Output is correct |
42 |
Correct |
10 ms |
3064 KB |
Output is correct |
43 |
Correct |
10 ms |
3064 KB |
Output is correct |
44 |
Correct |
10 ms |
3164 KB |
Output is correct |
45 |
Correct |
41 ms |
8804 KB |
Output is correct |
46 |
Correct |
34 ms |
8696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2552 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2592 KB |
Output is correct |
4 |
Correct |
4 ms |
2552 KB |
Output is correct |
5 |
Correct |
5 ms |
2552 KB |
Output is correct |
6 |
Correct |
4 ms |
2552 KB |
Output is correct |
7 |
Correct |
5 ms |
2552 KB |
Output is correct |
8 |
Correct |
4 ms |
2552 KB |
Output is correct |
9 |
Correct |
4 ms |
2552 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
5 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2552 KB |
Output is correct |
13 |
Correct |
4 ms |
2552 KB |
Output is correct |
14 |
Correct |
5 ms |
2808 KB |
Output is correct |
15 |
Correct |
6 ms |
2812 KB |
Output is correct |
16 |
Correct |
6 ms |
2552 KB |
Output is correct |
17 |
Correct |
7 ms |
2936 KB |
Output is correct |
18 |
Correct |
6 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
2680 KB |
Output is correct |
20 |
Correct |
5 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2652 KB |
Output is correct |
22 |
Correct |
5 ms |
2680 KB |
Output is correct |
23 |
Correct |
5 ms |
2680 KB |
Output is correct |
24 |
Correct |
6 ms |
2808 KB |
Output is correct |
25 |
Correct |
6 ms |
2808 KB |
Output is correct |
26 |
Correct |
5 ms |
2680 KB |
Output is correct |
27 |
Correct |
5 ms |
2680 KB |
Output is correct |
28 |
Correct |
5 ms |
2936 KB |
Output is correct |
29 |
Correct |
7 ms |
3320 KB |
Output is correct |
30 |
Correct |
5 ms |
2812 KB |
Output is correct |
31 |
Correct |
6 ms |
3064 KB |
Output is correct |
32 |
Correct |
5 ms |
2936 KB |
Output is correct |
33 |
Correct |
10 ms |
4008 KB |
Output is correct |
34 |
Correct |
9 ms |
3960 KB |
Output is correct |
35 |
Correct |
25 ms |
5240 KB |
Output is correct |
36 |
Correct |
7 ms |
3064 KB |
Output is correct |
37 |
Correct |
28 ms |
5932 KB |
Output is correct |
38 |
Correct |
32 ms |
6264 KB |
Output is correct |
39 |
Correct |
33 ms |
6264 KB |
Output is correct |
40 |
Correct |
33 ms |
6264 KB |
Output is correct |
41 |
Correct |
34 ms |
6192 KB |
Output is correct |
42 |
Correct |
10 ms |
3192 KB |
Output is correct |
43 |
Correct |
10 ms |
3064 KB |
Output is correct |
44 |
Correct |
10 ms |
3192 KB |
Output is correct |
45 |
Correct |
33 ms |
8824 KB |
Output is correct |
46 |
Correct |
35 ms |
8696 KB |
Output is correct |
47 |
Correct |
66 ms |
13392 KB |
Output is correct |
48 |
Correct |
29 ms |
6388 KB |
Output is correct |
49 |
Correct |
25 ms |
5368 KB |
Output is correct |
50 |
Correct |
16 ms |
4984 KB |
Output is correct |
51 |
Correct |
62 ms |
8480 KB |
Output is correct |
52 |
Correct |
54 ms |
9020 KB |
Output is correct |
53 |
Correct |
27 ms |
6132 KB |
Output is correct |
54 |
Correct |
6 ms |
3064 KB |
Output is correct |
55 |
Correct |
8 ms |
3444 KB |
Output is correct |
56 |
Correct |
21 ms |
5348 KB |
Output is correct |
57 |
Correct |
47 ms |
11640 KB |
Output is correct |
58 |
Correct |
14 ms |
3952 KB |
Output is correct |
59 |
Correct |
15 ms |
4468 KB |
Output is correct |
60 |
Correct |
17 ms |
5108 KB |
Output is correct |
61 |
Correct |
16 ms |
4472 KB |
Output is correct |
62 |
Correct |
35 ms |
9584 KB |
Output is correct |
63 |
Correct |
92 ms |
25840 KB |
Output is correct |
64 |
Correct |
102 ms |
28788 KB |
Output is correct |
65 |
Correct |
126 ms |
38736 KB |
Output is correct |
66 |
Correct |
232 ms |
65936 KB |
Output is correct |
67 |
Correct |
226 ms |
65864 KB |
Output is correct |