Submission #402533

# Submission time Handle Problem Language Result Execution time Memory
402533 2021-05-11T22:50:45 Z faresbasbs Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
488 ms 262148 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
bitset<30001> bs,bs2[30001];
vector<int> v[30001];
int n,m;

int main(){
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	cin >> n >> m;
	for(int i = 0 ; i < m ; i += 1){
		int a,b;
		cin >> a >> b;
		v[a].push_back(b);
	}
	queue<pair<int,int>> q;
	q.push({0,0});
	int dist = 0;
	while(q.size()){
		int f = q.size();
		queue<pair<int,int>> q2;
		while(q.size()){
			pair<int,int> a = q.front();
			q.pop();
			if(bs2[a.first][a.second]){
				continue;
			}
			if(!bs[a.first]){
				bs[a.first] = 1;
				for(auto i : v[a.first]){
					q.push({a.first,i});
				}
			}
			if(a.first+a.second < n){
				q2.push({a.first+a.second,a.second});
			}
			if(a.first-a.second >= 0){
				q2.push({a.first-a.second,a.second});
			}
		}
		q = q2;
		if(bs[1]){
			cout << dist << '\n';
			return 0;
		}
		dist += 1;
	}
	cout << -1 << endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:7: warning: unused variable 'f' [-Wunused-variable]
   22 |   int f = q.size();
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Runtime error 488 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Runtime error 455 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 972 KB Output is correct
2 Runtime error 469 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Runtime error 448 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1028 KB Output is correct
2 Runtime error 464 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -