답안 #48172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48172 2018-05-10T12:38:02 Z WA_TLE Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 63404 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);
	}
	unordered_set<int>used(n);
	deque<tuple<int,int,int,bool>>que;
	que.pub(mt(stb,stp,0,true));
	que.pub(mt(stb,stp,0,false));
	int ba=40000;
	used.ins(stb*ba+stp);
	
	while(que.size()>0){
		int b,p,t;bool mu;tie(b,p,t,mu)=que.front();
		que.pof();
		if(b==enb){cout<<t<<endl;return 0;}
		//cerr<<"de"<<b<<" "<<p<<" "<<t<<endl;
		used.ins(b*ba+p);
		if(go[b].size()>0){
			for(auto it:go[b]){que.puf(mt(b,it,t,true));que.puf(mt(b,it,t,false));}
			go[b].clear();
		}
		if(mu&&b+p<n&&used.count((b+p)*ba+p)==0){
			que.pub(mt(b+p,p,t+1,true));
			used.ins((b+p)*ba+p);
		}
		if((!mu)&&b-p>=0&&used.count((b-p)*ba+p)==0){
			que.pub(mt(b-p,p,t+1,false));
			used.ins((b-p)*ba+p);
		}
	}
	cout<<"-1"<<endl;
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:64:17: warning: 'stp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  used.ins(stb*ba+stp);
           ~~~~~~^~~~
skyscraper.cpp:64:14: warning: 'stb' may be used uninitialized in this function [-Wmaybe-uninitialized]
  used.ins(stb*ba+stp);
           ~~~^~~
skyscraper.cpp:69:3: warning: 'enb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(b==enb){cout<<t<<endl;return 0;}
   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 568 KB Output is correct
2 Correct 2 ms 568 KB Output is correct
3 Correct 2 ms 568 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 4 ms 868 KB Output is correct
15 Correct 3 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 868 KB Output is correct
2 Correct 2 ms 868 KB Output is correct
3 Correct 2 ms 868 KB Output is correct
4 Correct 2 ms 868 KB Output is correct
5 Correct 2 ms 868 KB Output is correct
6 Correct 2 ms 868 KB Output is correct
7 Correct 2 ms 868 KB Output is correct
8 Correct 2 ms 868 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 3 ms 868 KB Output is correct
12 Correct 3 ms 868 KB Output is correct
13 Correct 3 ms 868 KB Output is correct
14 Correct 4 ms 892 KB Output is correct
15 Correct 4 ms 892 KB Output is correct
16 Correct 3 ms 892 KB Output is correct
17 Correct 3 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 3 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 3 ms 892 KB Output is correct
24 Correct 4 ms 900 KB Output is correct
25 Correct 4 ms 900 KB Output is correct
26 Correct 3 ms 900 KB Output is correct
27 Correct 4 ms 900 KB Output is correct
28 Correct 8 ms 1660 KB Output is correct
29 Correct 14 ms 3156 KB Output is correct
30 Correct 5 ms 3156 KB Output is correct
31 Correct 9 ms 3156 KB Output is correct
32 Correct 7 ms 3156 KB Output is correct
33 Correct 28 ms 5656 KB Output is correct
34 Correct 15 ms 5656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5656 KB Output is correct
2 Correct 2 ms 5656 KB Output is correct
3 Correct 2 ms 5656 KB Output is correct
4 Correct 2 ms 5656 KB Output is correct
5 Correct 2 ms 5656 KB Output is correct
6 Correct 2 ms 5656 KB Output is correct
7 Correct 2 ms 5656 KB Output is correct
8 Correct 2 ms 5656 KB Output is correct
9 Correct 2 ms 5656 KB Output is correct
10 Correct 2 ms 5656 KB Output is correct
11 Correct 3 ms 5656 KB Output is correct
12 Correct 3 ms 5656 KB Output is correct
13 Correct 3 ms 5656 KB Output is correct
14 Correct 4 ms 5656 KB Output is correct
15 Correct 3 ms 5656 KB Output is correct
16 Correct 2 ms 5656 KB Output is correct
17 Correct 3 ms 5656 KB Output is correct
18 Correct 2 ms 5656 KB Output is correct
19 Correct 2 ms 5656 KB Output is correct
20 Correct 4 ms 5656 KB Output is correct
21 Correct 2 ms 5656 KB Output is correct
22 Correct 2 ms 5656 KB Output is correct
23 Correct 3 ms 5656 KB Output is correct
24 Correct 5 ms 5656 KB Output is correct
25 Correct 3 ms 5656 KB Output is correct
26 Correct 3 ms 5656 KB Output is correct
27 Correct 3 ms 5656 KB Output is correct
28 Correct 8 ms 5656 KB Output is correct
29 Correct 14 ms 5656 KB Output is correct
30 Correct 5 ms 5656 KB Output is correct
31 Correct 10 ms 5656 KB Output is correct
32 Correct 7 ms 5656 KB Output is correct
33 Correct 26 ms 5656 KB Output is correct
34 Correct 16 ms 5656 KB Output is correct
35 Correct 31 ms 5656 KB Output is correct
36 Correct 5 ms 5656 KB Output is correct
37 Correct 22 ms 5656 KB Output is correct
38 Correct 24 ms 5656 KB Output is correct
39 Correct 19 ms 5656 KB Output is correct
40 Correct 20 ms 5656 KB Output is correct
41 Correct 31 ms 5656 KB Output is correct
42 Correct 17 ms 5656 KB Output is correct
43 Correct 17 ms 5656 KB Output is correct
44 Correct 21 ms 5656 KB Output is correct
45 Correct 266 ms 20896 KB Output is correct
46 Correct 104 ms 20896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 20896 KB Output is correct
2 Correct 2 ms 20896 KB Output is correct
3 Correct 2 ms 20896 KB Output is correct
4 Correct 2 ms 20896 KB Output is correct
5 Correct 2 ms 20896 KB Output is correct
6 Correct 2 ms 20896 KB Output is correct
7 Correct 2 ms 20896 KB Output is correct
8 Correct 2 ms 20896 KB Output is correct
9 Correct 2 ms 20896 KB Output is correct
10 Correct 2 ms 20896 KB Output is correct
11 Correct 3 ms 20896 KB Output is correct
12 Correct 3 ms 20896 KB Output is correct
13 Correct 3 ms 20896 KB Output is correct
14 Correct 4 ms 20896 KB Output is correct
15 Correct 3 ms 20896 KB Output is correct
16 Correct 2 ms 20896 KB Output is correct
17 Correct 3 ms 20896 KB Output is correct
18 Correct 2 ms 20896 KB Output is correct
19 Correct 2 ms 20896 KB Output is correct
20 Correct 3 ms 20896 KB Output is correct
21 Correct 2 ms 20896 KB Output is correct
22 Correct 2 ms 20896 KB Output is correct
23 Correct 3 ms 20896 KB Output is correct
24 Correct 4 ms 20896 KB Output is correct
25 Correct 3 ms 20896 KB Output is correct
26 Correct 3 ms 20896 KB Output is correct
27 Correct 3 ms 20896 KB Output is correct
28 Correct 8 ms 20896 KB Output is correct
29 Correct 14 ms 20896 KB Output is correct
30 Correct 5 ms 20896 KB Output is correct
31 Correct 9 ms 20896 KB Output is correct
32 Correct 7 ms 20896 KB Output is correct
33 Correct 28 ms 20896 KB Output is correct
34 Correct 16 ms 20896 KB Output is correct
35 Correct 29 ms 20896 KB Output is correct
36 Correct 5 ms 20896 KB Output is correct
37 Correct 22 ms 20896 KB Output is correct
38 Correct 24 ms 20896 KB Output is correct
39 Correct 19 ms 20896 KB Output is correct
40 Correct 20 ms 20896 KB Output is correct
41 Correct 32 ms 20896 KB Output is correct
42 Correct 17 ms 20896 KB Output is correct
43 Correct 18 ms 20896 KB Output is correct
44 Correct 21 ms 20896 KB Output is correct
45 Correct 251 ms 20972 KB Output is correct
46 Correct 103 ms 20972 KB Output is correct
47 Correct 21 ms 20972 KB Output is correct
48 Correct 19 ms 20972 KB Output is correct
49 Correct 18 ms 20972 KB Output is correct
50 Correct 16 ms 20972 KB Output is correct
51 Correct 39 ms 20972 KB Output is correct
52 Correct 45 ms 20972 KB Output is correct
53 Correct 27 ms 20972 KB Output is correct
54 Correct 4 ms 20972 KB Output is correct
55 Correct 6 ms 20972 KB Output is correct
56 Correct 31 ms 20972 KB Output is correct
57 Correct 4 ms 20972 KB Output is correct
58 Correct 30 ms 20972 KB Output is correct
59 Correct 30 ms 20972 KB Output is correct
60 Correct 28 ms 20972 KB Output is correct
61 Correct 29 ms 20972 KB Output is correct
62 Correct 235 ms 20972 KB Output is correct
63 Execution timed out 1088 ms 63404 KB Time limit exceeded
64 Halted 0 ms 0 KB -