Submission #48032

# Submission time Handle Problem Language Result Execution time Memory
48032 2018-05-09T12:43:21 Z WA_TLE Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 60532 KB
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
//cin.tie(0);
//ios::sync_with_stdio(false);
const llint mod=1000000007;
const llint big=4.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<int>&ar,llint in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<int>&ar,llint in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	//0-1 dfs
	int n,m,i;cin>>n>>m;
	vector<vector<int>>go(n);
	int stb,stp,enb;
	for(i=0;i<m;i++){
		int b,p;cin>>b>>p;
		if(i==0){stb=b;stp=p;}
		if(i==1){enb=b;}
		go[b].pub(p);
	}
	vector<unordered_set<int>>used(n);
	deque<tuple<int,int,int>>que;
	que.pub(mt(stb,stp,0));
	used[stb].ins(stp);
	while(que.size()>0){
		int b,p,t;tie(b,p,t)=que.front();
		que.pof();
		if(b==enb){cout<<t<<endl;return 0;}
		//cerr<<"de"<<b<<" "<<p<<" "<<t<<endl;
		used[b].ins(p);
		if(go[b].size()>0){
			for(auto it:go[b]){que.puf(mt(b,it,t));}
			go[b].clear();
		}
		if(b+p<n&&used[b+p].count(p)==0){
			que.pub(mt(b+p,p,t+1));
			used[b+p].ins(p);
		}
		if(b-p>=0&&used[b-p].count(p)==0){
			que.pub(mt(b-p,p,t+1));
			used[b-p].ins(p);
		}
	}
	cout<<"-1"<<endl;
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:62:10: warning: 'stb' may be used uninitialized in this function [-Wmaybe-uninitialized]
  used[stb].ins(stp);
          ^
skyscraper.cpp:66:3: warning: 'enb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(b==enb){cout<<t<<endl;return 0;}
   ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 2 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 560 KB Output is correct
2 Correct 2 ms 560 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 4 ms 612 KB Output is correct
12 Correct 4 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 4 ms 876 KB Output is correct
15 Correct 3 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 2 ms 876 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 3 ms 876 KB Output is correct
12 Correct 3 ms 876 KB Output is correct
13 Correct 3 ms 876 KB Output is correct
14 Correct 4 ms 892 KB Output is correct
15 Correct 3 ms 892 KB Output is correct
16 Correct 2 ms 892 KB Output is correct
17 Correct 4 ms 892 KB Output is correct
18 Correct 2 ms 892 KB Output is correct
19 Correct 2 ms 892 KB Output is correct
20 Correct 4 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 4 ms 892 KB Output is correct
24 Correct 5 ms 1020 KB Output is correct
25 Correct 3 ms 1020 KB Output is correct
26 Correct 4 ms 1020 KB Output is correct
27 Correct 4 ms 1020 KB Output is correct
28 Correct 9 ms 1660 KB Output is correct
29 Correct 19 ms 3324 KB Output is correct
30 Correct 6 ms 3324 KB Output is correct
31 Correct 11 ms 3324 KB Output is correct
32 Correct 8 ms 3324 KB Output is correct
33 Correct 40 ms 5756 KB Output is correct
34 Correct 24 ms 5756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5756 KB Output is correct
2 Correct 2 ms 5756 KB Output is correct
3 Correct 2 ms 5756 KB Output is correct
4 Correct 2 ms 5756 KB Output is correct
5 Correct 2 ms 5756 KB Output is correct
6 Correct 2 ms 5756 KB Output is correct
7 Correct 2 ms 5756 KB Output is correct
8 Correct 2 ms 5756 KB Output is correct
9 Correct 2 ms 5756 KB Output is correct
10 Correct 2 ms 5756 KB Output is correct
11 Correct 3 ms 5756 KB Output is correct
12 Correct 2 ms 5756 KB Output is correct
13 Correct 3 ms 5756 KB Output is correct
14 Correct 4 ms 5756 KB Output is correct
15 Correct 3 ms 5756 KB Output is correct
16 Correct 2 ms 5756 KB Output is correct
17 Correct 4 ms 5756 KB Output is correct
18 Correct 2 ms 5756 KB Output is correct
19 Correct 2 ms 5756 KB Output is correct
20 Correct 4 ms 5756 KB Output is correct
21 Correct 2 ms 5756 KB Output is correct
22 Correct 2 ms 5756 KB Output is correct
23 Correct 4 ms 5756 KB Output is correct
24 Correct 5 ms 5756 KB Output is correct
25 Correct 3 ms 5756 KB Output is correct
26 Correct 4 ms 5756 KB Output is correct
27 Correct 4 ms 5756 KB Output is correct
28 Correct 9 ms 5756 KB Output is correct
29 Correct 19 ms 5756 KB Output is correct
30 Correct 6 ms 5756 KB Output is correct
31 Correct 11 ms 5756 KB Output is correct
32 Correct 9 ms 5756 KB Output is correct
33 Correct 42 ms 5824 KB Output is correct
34 Correct 23 ms 5824 KB Output is correct
35 Correct 29 ms 5824 KB Output is correct
36 Correct 5 ms 5824 KB Output is correct
37 Correct 22 ms 5824 KB Output is correct
38 Correct 25 ms 5824 KB Output is correct
39 Correct 19 ms 5824 KB Output is correct
40 Correct 22 ms 5824 KB Output is correct
41 Correct 22 ms 5824 KB Output is correct
42 Correct 17 ms 5824 KB Output is correct
43 Correct 20 ms 5824 KB Output is correct
44 Correct 19 ms 5824 KB Output is correct
45 Correct 260 ms 21248 KB Output is correct
46 Correct 127 ms 21248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 21248 KB Output is correct
2 Correct 2 ms 21248 KB Output is correct
3 Correct 3 ms 21248 KB Output is correct
4 Correct 2 ms 21248 KB Output is correct
5 Correct 2 ms 21248 KB Output is correct
6 Correct 2 ms 21248 KB Output is correct
7 Correct 2 ms 21248 KB Output is correct
8 Correct 2 ms 21248 KB Output is correct
9 Correct 2 ms 21248 KB Output is correct
10 Correct 2 ms 21248 KB Output is correct
11 Correct 3 ms 21248 KB Output is correct
12 Correct 3 ms 21248 KB Output is correct
13 Correct 3 ms 21248 KB Output is correct
14 Correct 4 ms 21248 KB Output is correct
15 Correct 3 ms 21248 KB Output is correct
16 Correct 2 ms 21248 KB Output is correct
17 Correct 4 ms 21248 KB Output is correct
18 Correct 2 ms 21248 KB Output is correct
19 Correct 2 ms 21248 KB Output is correct
20 Correct 3 ms 21248 KB Output is correct
21 Correct 2 ms 21248 KB Output is correct
22 Correct 2 ms 21248 KB Output is correct
23 Correct 4 ms 21248 KB Output is correct
24 Correct 5 ms 21248 KB Output is correct
25 Correct 3 ms 21248 KB Output is correct
26 Correct 4 ms 21248 KB Output is correct
27 Correct 4 ms 21248 KB Output is correct
28 Correct 9 ms 21248 KB Output is correct
29 Correct 20 ms 21248 KB Output is correct
30 Correct 6 ms 21248 KB Output is correct
31 Correct 11 ms 21248 KB Output is correct
32 Correct 8 ms 21248 KB Output is correct
33 Correct 39 ms 21248 KB Output is correct
34 Correct 24 ms 21248 KB Output is correct
35 Correct 29 ms 21248 KB Output is correct
36 Correct 5 ms 21248 KB Output is correct
37 Correct 22 ms 21248 KB Output is correct
38 Correct 25 ms 21248 KB Output is correct
39 Correct 19 ms 21248 KB Output is correct
40 Correct 21 ms 21248 KB Output is correct
41 Correct 22 ms 21248 KB Output is correct
42 Correct 17 ms 21248 KB Output is correct
43 Correct 18 ms 21248 KB Output is correct
44 Correct 19 ms 21248 KB Output is correct
45 Correct 254 ms 21424 KB Output is correct
46 Correct 113 ms 21424 KB Output is correct
47 Correct 23 ms 21424 KB Output is correct
48 Correct 21 ms 21424 KB Output is correct
49 Correct 19 ms 21424 KB Output is correct
50 Correct 14 ms 21424 KB Output is correct
51 Correct 45 ms 21424 KB Output is correct
52 Correct 48 ms 21424 KB Output is correct
53 Correct 29 ms 21424 KB Output is correct
54 Correct 7 ms 21424 KB Output is correct
55 Correct 10 ms 21424 KB Output is correct
56 Correct 32 ms 21424 KB Output is correct
57 Correct 5 ms 21424 KB Output is correct
58 Correct 33 ms 21424 KB Output is correct
59 Correct 34 ms 21424 KB Output is correct
60 Correct 33 ms 21424 KB Output is correct
61 Correct 34 ms 21424 KB Output is correct
62 Correct 323 ms 23776 KB Output is correct
63 Execution timed out 1078 ms 60532 KB Time limit exceeded
64 Halted 0 ms 0 KB -