Submission #535829

# Submission time Handle Problem Language Result Execution time Memory
535829 2022-03-11T12:23:05 Z PoPularPlusPlus Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 42524 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 998244353; 
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}

//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);

void solve(){
	int n , m1;
	cin >> n >> m1;
	vector<vector<int>> v(n);
	map<pair<int,int>,int> m;
	int dis[n];
	memset(dis,0,sizeof dis);
	int s , e;
	for(int i = 0; i < m1; i++){
		int b,p;
		cin >> b >> p;
		if(i == 0)s = b;
		v[b].pb(p);
		if(i == 1)e = b;
	}
	queue<array<int,3>> q;
	memset(dis,-1,sizeof dis);
	dis[s] = 0;
	for(int i : v[s]){
		if(m[{s,i}] == 0){
			array<int,3> lol = {s,i,0};
			q.push(lol);
		}
	}
	while(q.size()){
		array<int,3> p = q.front();
		q.pop();
		if(p[0] + p[1] < n && m[{p[0]+p[1] , p[1]}] == 0){
			m[{p[0]+p[1] , p[1]}] = 1;
			array<int,3> lol = {p[0]+p[1],p[1],p[2]+1};
			q.push(lol);
			if(dis[p[0]+p[1]] == -1){
				dis[p[0]+p[1]] = p[2]+1;
				for(int i : v[p[0]+p[1]]){
					if(m[{p[0]+p[1],i}]==0){
						array<int,3> again = {p[0]+p[1] , i , dis[p[0]+p[1]]};
						q.push(again);
					}
				}
			}
		}
		if(p[0] - p[1] >=0 && m[{p[0]-p[1] , p[1]}] == 0){
			m[{p[0]-p[1] , p[1]}] = 1;
			array<int,3> lol = {p[0]-p[1],p[1],p[2]+1};
			q.push(lol);
			if(dis[p[0]-p[1]] == -1){
				dis[p[0]-p[1]] = p[2]+1;
				for(int i : v[p[0]-p[1]]){
					if(m[{p[0]-p[1],i}] == 0){
						array<int,3> again = {p[0]-p[1] , i , dis[p[0]-p[1]]};
						q.push(again);
					}
				}
			}
		}
	}
	cout << dis[e] << '\n';
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	//int t;cin >> t;while(t--)
	solve();
	return 0;
}

Compilation message

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:77:20: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |  cout << dis[e] << '\n';
      |                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 4 ms 712 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 9 ms 1236 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 8 ms 1180 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 11 ms 1876 KB Output is correct
29 Correct 35 ms 4156 KB Output is correct
30 Correct 7 ms 1408 KB Output is correct
31 Correct 15 ms 2448 KB Output is correct
32 Correct 10 ms 1736 KB Output is correct
33 Correct 93 ms 7792 KB Output is correct
34 Correct 85 ms 7900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 584 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 4 ms 724 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 8 ms 1236 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 472 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 4 ms 860 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 10 ms 1876 KB Output is correct
29 Correct 38 ms 4180 KB Output is correct
30 Correct 8 ms 1376 KB Output is correct
31 Correct 16 ms 2400 KB Output is correct
32 Correct 11 ms 1760 KB Output is correct
33 Correct 97 ms 8000 KB Output is correct
34 Correct 86 ms 7900 KB Output is correct
35 Correct 77 ms 7108 KB Output is correct
36 Correct 12 ms 1492 KB Output is correct
37 Correct 181 ms 11472 KB Output is correct
38 Correct 170 ms 10868 KB Output is correct
39 Correct 167 ms 10928 KB Output is correct
40 Correct 170 ms 10848 KB Output is correct
41 Correct 150 ms 10852 KB Output is correct
42 Correct 7 ms 1108 KB Output is correct
43 Correct 13 ms 1364 KB Output is correct
44 Correct 6 ms 836 KB Output is correct
45 Correct 543 ms 30772 KB Output is correct
46 Correct 563 ms 30888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 3 ms 728 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 9 ms 1236 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 8 ms 1104 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Correct 3 ms 848 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 11 ms 1828 KB Output is correct
29 Correct 31 ms 4092 KB Output is correct
30 Correct 8 ms 1364 KB Output is correct
31 Correct 17 ms 2384 KB Output is correct
32 Correct 10 ms 1772 KB Output is correct
33 Correct 98 ms 7792 KB Output is correct
34 Correct 101 ms 7876 KB Output is correct
35 Correct 72 ms 7156 KB Output is correct
36 Correct 11 ms 1620 KB Output is correct
37 Correct 194 ms 11408 KB Output is correct
38 Correct 171 ms 10860 KB Output is correct
39 Correct 142 ms 10892 KB Output is correct
40 Correct 167 ms 10952 KB Output is correct
41 Correct 156 ms 10788 KB Output is correct
42 Correct 8 ms 1108 KB Output is correct
43 Correct 8 ms 1260 KB Output is correct
44 Correct 5 ms 852 KB Output is correct
45 Correct 596 ms 30872 KB Output is correct
46 Correct 603 ms 30832 KB Output is correct
47 Execution timed out 1091 ms 42524 KB Time limit exceeded
48 Halted 0 ms 0 KB -