Submission #563563

# Submission time Handle Problem Language Result Execution time Memory
563563 2022-05-17T13:53:28 Z myrcella Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
374 ms 112380 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 3e4+10;

int n,m;
vector <int> power[maxn];
deque <pair<int,pii>> q;
bitset <maxn> vis[maxn];

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie();
	cin>>n>>m;
	int des;
	rep(i,0,m) {
		int x,y;
		cin>>x>>y;
		power[x].pb(y);
		if (i==0) q.push_back({0,{x,y}}); 
		if (i==1) des=x;
	}
	while (!q.empty()) {
		int d = q.front().fi;
		int x = q.front().se.fi, y = q.front().se.se;
		q.pop_front();
		if (vis[x][y]==1) continue;
//		cout<<x<<" "<<y<<endl;
		vis[x][y] = 1;
		if (x==des) {
			cout<<d;
			return 0;
		}
		if (x+y<n and vis[x+y][y]==0) q.push_back({d+1,{x+y,y}});
		if (x-y>=0 and vis[x-y][y]==0) q.push_back({d+1,{x-y,y}});
		for (auto it:power[x]) {
			if (vis[x][it]==0) q.push_front({d,{x,it}});
		}
	}
	cout<<-1;
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:3: warning: 'des' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |   if (x==des) {
      |   ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1036 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1040 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1036 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 1036 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1032 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1424 KB Output is correct
14 Correct 2 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1432 KB Output is correct
14 Correct 2 ms 1428 KB Output is correct
15 Correct 3 ms 1312 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 2 ms 1044 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 4 ms 6356 KB Output is correct
24 Correct 5 ms 7508 KB Output is correct
25 Correct 2 ms 2388 KB Output is correct
26 Correct 5 ms 7316 KB Output is correct
27 Correct 5 ms 7704 KB Output is correct
28 Correct 6 ms 8404 KB Output is correct
29 Correct 8 ms 8276 KB Output is correct
30 Correct 5 ms 8276 KB Output is correct
31 Correct 6 ms 8276 KB Output is correct
32 Correct 6 ms 8332 KB Output is correct
33 Correct 7 ms 8340 KB Output is correct
34 Correct 6 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1020 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1036 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 2 ms 1364 KB Output is correct
14 Correct 2 ms 1364 KB Output is correct
15 Correct 2 ms 1364 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 1036 KB Output is correct
20 Correct 5 ms 8456 KB Output is correct
21 Correct 1 ms 1040 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 5 ms 6356 KB Output is correct
24 Correct 6 ms 7452 KB Output is correct
25 Correct 2 ms 2388 KB Output is correct
26 Correct 5 ms 7252 KB Output is correct
27 Correct 5 ms 7636 KB Output is correct
28 Correct 8 ms 8376 KB Output is correct
29 Correct 6 ms 8336 KB Output is correct
30 Correct 6 ms 8276 KB Output is correct
31 Correct 6 ms 8276 KB Output is correct
32 Correct 5 ms 8276 KB Output is correct
33 Correct 8 ms 8404 KB Output is correct
34 Correct 6 ms 8340 KB Output is correct
35 Correct 11 ms 6808 KB Output is correct
36 Correct 3 ms 2260 KB Output is correct
37 Correct 9 ms 6552 KB Output is correct
38 Correct 10 ms 4812 KB Output is correct
39 Correct 9 ms 1620 KB Output is correct
40 Correct 8 ms 2444 KB Output is correct
41 Correct 8 ms 3156 KB Output is correct
42 Correct 8 ms 7636 KB Output is correct
43 Correct 9 ms 8008 KB Output is correct
44 Correct 9 ms 8788 KB Output is correct
45 Correct 39 ms 9344 KB Output is correct
46 Correct 34 ms 9280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1032 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1040 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1424 KB Output is correct
14 Correct 2 ms 1364 KB Output is correct
15 Correct 2 ms 1300 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 6 ms 8376 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1036 KB Output is correct
23 Correct 4 ms 6356 KB Output is correct
24 Correct 6 ms 7448 KB Output is correct
25 Correct 2 ms 2388 KB Output is correct
26 Correct 6 ms 7332 KB Output is correct
27 Correct 5 ms 7636 KB Output is correct
28 Correct 7 ms 8348 KB Output is correct
29 Correct 6 ms 8404 KB Output is correct
30 Correct 7 ms 8296 KB Output is correct
31 Correct 6 ms 8332 KB Output is correct
32 Correct 6 ms 8276 KB Output is correct
33 Correct 8 ms 8404 KB Output is correct
34 Correct 6 ms 8404 KB Output is correct
35 Correct 14 ms 6800 KB Output is correct
36 Correct 3 ms 2260 KB Output is correct
37 Correct 9 ms 6588 KB Output is correct
38 Correct 10 ms 4876 KB Output is correct
39 Correct 7 ms 1540 KB Output is correct
40 Correct 7 ms 2516 KB Output is correct
41 Correct 10 ms 3156 KB Output is correct
42 Correct 9 ms 7644 KB Output is correct
43 Correct 8 ms 8092 KB Output is correct
44 Correct 9 ms 8784 KB Output is correct
45 Correct 40 ms 9420 KB Output is correct
46 Correct 35 ms 9288 KB Output is correct
47 Correct 14 ms 10392 KB Output is correct
48 Correct 6 ms 1656 KB Output is correct
49 Correct 6 ms 1688 KB Output is correct
50 Correct 7 ms 1492 KB Output is correct
51 Correct 60 ms 81816 KB Output is correct
52 Correct 66 ms 89672 KB Output is correct
53 Correct 20 ms 18764 KB Output is correct
54 Correct 33 ms 61180 KB Output is correct
55 Correct 44 ms 77788 KB Output is correct
56 Correct 70 ms 112300 KB Output is correct
57 Correct 2 ms 2644 KB Output is correct
58 Correct 66 ms 111676 KB Output is correct
59 Correct 65 ms 103824 KB Output is correct
60 Correct 65 ms 103732 KB Output is correct
61 Correct 63 ms 98760 KB Output is correct
62 Correct 101 ms 112380 KB Output is correct
63 Correct 192 ms 111884 KB Output is correct
64 Correct 183 ms 111764 KB Output is correct
65 Correct 238 ms 112008 KB Output is correct
66 Correct 374 ms 112240 KB Output is correct
67 Correct 229 ms 112096 KB Output is correct