Submission #535830

# Submission time Handle Problem Language Result Execution time Memory
535830 2022-03-11T12:34:59 Z PoPularPlusPlus Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 41308 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){
			m[{s,i}] = 1;
			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){
						m[{p[0]+p[1],i}] = 1;
						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){
						m[{p[0]-p[1],i}] = 1;
						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:80:20: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   80 |  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 1 ms 256 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 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 4 ms 596 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 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 4 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 9 ms 1260 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 7 ms 1108 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 724 KB Output is correct
28 Correct 13 ms 1748 KB Output is correct
29 Correct 37 ms 4152 KB Output is correct
30 Correct 8 ms 1364 KB Output is correct
31 Correct 17 ms 2412 KB Output is correct
32 Correct 11 ms 1748 KB Output is correct
33 Correct 76 ms 7868 KB Output is correct
34 Correct 79 ms 7784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 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 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 7 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 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 7 ms 1108 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 4 ms 724 KB Output is correct
28 Correct 11 ms 1748 KB Output is correct
29 Correct 31 ms 4060 KB Output is correct
30 Correct 8 ms 1364 KB Output is correct
31 Correct 15 ms 2420 KB Output is correct
32 Correct 14 ms 1728 KB Output is correct
33 Correct 77 ms 7816 KB Output is correct
34 Correct 81 ms 7804 KB Output is correct
35 Correct 107 ms 6896 KB Output is correct
36 Correct 11 ms 1492 KB Output is correct
37 Correct 160 ms 11236 KB Output is correct
38 Correct 137 ms 10660 KB Output is correct
39 Correct 148 ms 10648 KB Output is correct
40 Correct 163 ms 10572 KB Output is correct
41 Correct 137 ms 10652 KB Output is correct
42 Correct 8 ms 980 KB Output is correct
43 Correct 7 ms 852 KB Output is correct
44 Correct 7 ms 596 KB Output is correct
45 Correct 551 ms 30648 KB Output is correct
46 Correct 602 ms 30656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 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 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 10 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 7 ms 1108 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 13 ms 1780 KB Output is correct
29 Correct 34 ms 4180 KB Output is correct
30 Correct 8 ms 1428 KB Output is correct
31 Correct 16 ms 2388 KB Output is correct
32 Correct 12 ms 1784 KB Output is correct
33 Correct 88 ms 7868 KB Output is correct
34 Correct 89 ms 7884 KB Output is correct
35 Correct 81 ms 6876 KB Output is correct
36 Correct 12 ms 1492 KB Output is correct
37 Correct 189 ms 11296 KB Output is correct
38 Correct 158 ms 10600 KB Output is correct
39 Correct 162 ms 10576 KB Output is correct
40 Correct 184 ms 10572 KB Output is correct
41 Correct 163 ms 10644 KB Output is correct
42 Correct 8 ms 980 KB Output is correct
43 Correct 10 ms 868 KB Output is correct
44 Correct 7 ms 596 KB Output is correct
45 Correct 526 ms 30628 KB Output is correct
46 Correct 596 ms 30728 KB Output is correct
47 Execution timed out 1095 ms 41308 KB Time limit exceeded
48 Halted 0 ms 0 KB -