Submission #47260

# Submission time Handle Problem Language Result Execution time Memory
47260 2018-04-29T18:46:10 Z yusufake Jakarta Skyscrapers (APIO15_skyscraper) C++
57 / 100
1000 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int N   = 3e4 + 4;
const int kok = 177;
typedef long long ll;
typedef pair < int , int > pp;

vector < pp > Q[N*kok];
vector < int > V[N];
int H[N][kok],F[N],beg[N],jum[N],n,m,i,j,x,u,res,ss;

void f(int x, int u, int t){
	if(u >= kok){
		for(int i=0;i<kok;i++){
			if(x + i*u < n && !H[x+i*u][0])
				ss++, Q[t+i].pb(mp(x+i*u,0));
			if(x - i*u >= 0 && !H[x-i*u][0])
				ss++, Q[t+i].pb(mp(x-i*u,0));
		}		
	}
	else if(!H[x][u]) ss++, Q[t].pb(mp(x,u));
}

int main(){
	cin >> n >> m;
	for(i=0;i<m;i++){
		scanf("%d%d",&beg[i],&jum[i]);
		V[ beg[i] ].pb( jum[i] );
	}		
	
	f(beg[0],jum[0],0);
for(res=0 ; ss ; res++)
	for(i=0;i<Q[res].size();i++,ss--){
     	x = Q[res][i].st;
		u = Q[res][i].nd;
		if(x == beg[1]) { cout << res; return 0; }
		H[x][u] = 1;
		if(u){ if(x+u<n && !H[x+u][u])ss++,Q[res+1].pb(mp(x+u,u)); 
		if(x-u>=0 && !H[x-u][u])ss++,Q[res+1].pb(mp(x-u,u));  } 
		if(F[x]) continue;
		F[x] = 1;
		for(j=0;j<V[x].size();j++)
			f(x,V[x][j],res);
 	}		
	
	cout << -1;
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<Q[res].size();i++,ss--){
          ~^~~~~~~~~~~~~~
skyscraper.cpp:48:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<V[x].size();j++)
           ~^~~~~~~~~~~~
skyscraper.cpp:38:1: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 for(res=0 ; ss ; res++)
 ^~~
skyscraper.cpp:52:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  cout << -1;
  ^~~~
skyscraper.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&beg[i],&jum[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 119 ms 125816 KB Output is correct
2 Correct 109 ms 125916 KB Output is correct
3 Correct 102 ms 125916 KB Output is correct
4 Correct 103 ms 126008 KB Output is correct
5 Correct 107 ms 126008 KB Output is correct
6 Correct 101 ms 126008 KB Output is correct
7 Correct 101 ms 126008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 126008 KB Output is correct
2 Correct 102 ms 126008 KB Output is correct
3 Correct 104 ms 126052 KB Output is correct
4 Correct 108 ms 126052 KB Output is correct
5 Correct 100 ms 126052 KB Output is correct
6 Correct 101 ms 126052 KB Output is correct
7 Correct 105 ms 126052 KB Output is correct
8 Correct 101 ms 126052 KB Output is correct
9 Correct 101 ms 126132 KB Output is correct
10 Correct 100 ms 126132 KB Output is correct
11 Correct 103 ms 126132 KB Output is correct
12 Correct 103 ms 126132 KB Output is correct
13 Correct 101 ms 126132 KB Output is correct
14 Correct 105 ms 126220 KB Output is correct
15 Correct 100 ms 126220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 126220 KB Output is correct
2 Correct 102 ms 126220 KB Output is correct
3 Correct 107 ms 126220 KB Output is correct
4 Correct 102 ms 126220 KB Output is correct
5 Correct 102 ms 126220 KB Output is correct
6 Correct 101 ms 126220 KB Output is correct
7 Correct 101 ms 126220 KB Output is correct
8 Correct 101 ms 126220 KB Output is correct
9 Correct 101 ms 126220 KB Output is correct
10 Correct 109 ms 126220 KB Output is correct
11 Correct 102 ms 126220 KB Output is correct
12 Correct 101 ms 126220 KB Output is correct
13 Correct 102 ms 126220 KB Output is correct
14 Correct 102 ms 126220 KB Output is correct
15 Correct 104 ms 126324 KB Output is correct
16 Correct 103 ms 126324 KB Output is correct
17 Correct 102 ms 126588 KB Output is correct
18 Correct 101 ms 126588 KB Output is correct
19 Correct 102 ms 126588 KB Output is correct
20 Correct 103 ms 127484 KB Output is correct
21 Correct 101 ms 127484 KB Output is correct
22 Correct 102 ms 127484 KB Output is correct
23 Correct 101 ms 127484 KB Output is correct
24 Correct 104 ms 127484 KB Output is correct
25 Correct 101 ms 127484 KB Output is correct
26 Correct 101 ms 127484 KB Output is correct
27 Correct 102 ms 127508 KB Output is correct
28 Correct 104 ms 127996 KB Output is correct
29 Correct 103 ms 128124 KB Output is correct
30 Correct 102 ms 128124 KB Output is correct
31 Correct 108 ms 128124 KB Output is correct
32 Correct 104 ms 128124 KB Output is correct
33 Correct 106 ms 128632 KB Output is correct
34 Correct 110 ms 128632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 128632 KB Output is correct
2 Correct 100 ms 128632 KB Output is correct
3 Correct 99 ms 128632 KB Output is correct
4 Correct 107 ms 128632 KB Output is correct
5 Correct 102 ms 128632 KB Output is correct
6 Correct 99 ms 128632 KB Output is correct
7 Correct 107 ms 128632 KB Output is correct
8 Correct 103 ms 128632 KB Output is correct
9 Correct 99 ms 128632 KB Output is correct
10 Correct 103 ms 128632 KB Output is correct
11 Correct 100 ms 128632 KB Output is correct
12 Correct 99 ms 128632 KB Output is correct
13 Correct 102 ms 128632 KB Output is correct
14 Correct 101 ms 128632 KB Output is correct
15 Correct 103 ms 128632 KB Output is correct
16 Correct 100 ms 128632 KB Output is correct
17 Correct 103 ms 128632 KB Output is correct
18 Correct 102 ms 128632 KB Output is correct
19 Correct 100 ms 128632 KB Output is correct
20 Correct 102 ms 128632 KB Output is correct
21 Correct 99 ms 128632 KB Output is correct
22 Correct 102 ms 128632 KB Output is correct
23 Correct 104 ms 128632 KB Output is correct
24 Correct 105 ms 128632 KB Output is correct
25 Correct 102 ms 128632 KB Output is correct
26 Correct 103 ms 128632 KB Output is correct
27 Correct 105 ms 128632 KB Output is correct
28 Correct 103 ms 128632 KB Output is correct
29 Correct 104 ms 128632 KB Output is correct
30 Correct 104 ms 128632 KB Output is correct
31 Correct 108 ms 128632 KB Output is correct
32 Correct 101 ms 128632 KB Output is correct
33 Correct 107 ms 128632 KB Output is correct
34 Correct 103 ms 128632 KB Output is correct
35 Correct 115 ms 128632 KB Output is correct
36 Correct 102 ms 128632 KB Output is correct
37 Correct 110 ms 128632 KB Output is correct
38 Correct 122 ms 128632 KB Output is correct
39 Correct 115 ms 128632 KB Output is correct
40 Correct 110 ms 128632 KB Output is correct
41 Correct 112 ms 128632 KB Output is correct
42 Correct 108 ms 128632 KB Output is correct
43 Correct 109 ms 128632 KB Output is correct
44 Correct 118 ms 128632 KB Output is correct
45 Correct 133 ms 132184 KB Output is correct
46 Correct 121 ms 132184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 132184 KB Output is correct
2 Correct 103 ms 132184 KB Output is correct
3 Correct 110 ms 132184 KB Output is correct
4 Correct 99 ms 132184 KB Output is correct
5 Correct 101 ms 132184 KB Output is correct
6 Correct 102 ms 132184 KB Output is correct
7 Correct 104 ms 132184 KB Output is correct
8 Correct 99 ms 132184 KB Output is correct
9 Correct 105 ms 132184 KB Output is correct
10 Correct 105 ms 132184 KB Output is correct
11 Correct 100 ms 132184 KB Output is correct
12 Correct 106 ms 132184 KB Output is correct
13 Correct 105 ms 132184 KB Output is correct
14 Correct 100 ms 132184 KB Output is correct
15 Correct 103 ms 132184 KB Output is correct
16 Correct 106 ms 132184 KB Output is correct
17 Correct 106 ms 132184 KB Output is correct
18 Correct 108 ms 132184 KB Output is correct
19 Correct 100 ms 132184 KB Output is correct
20 Correct 107 ms 132184 KB Output is correct
21 Correct 107 ms 132184 KB Output is correct
22 Correct 111 ms 132184 KB Output is correct
23 Correct 109 ms 132184 KB Output is correct
24 Correct 107 ms 132184 KB Output is correct
25 Correct 108 ms 132184 KB Output is correct
26 Correct 107 ms 132184 KB Output is correct
27 Correct 108 ms 132184 KB Output is correct
28 Correct 112 ms 132184 KB Output is correct
29 Correct 127 ms 132184 KB Output is correct
30 Correct 103 ms 132184 KB Output is correct
31 Correct 122 ms 132184 KB Output is correct
32 Correct 103 ms 132184 KB Output is correct
33 Correct 112 ms 132184 KB Output is correct
34 Correct 107 ms 132184 KB Output is correct
35 Correct 119 ms 132184 KB Output is correct
36 Correct 115 ms 132184 KB Output is correct
37 Correct 130 ms 132184 KB Output is correct
38 Correct 117 ms 132184 KB Output is correct
39 Correct 115 ms 132184 KB Output is correct
40 Correct 111 ms 132184 KB Output is correct
41 Correct 116 ms 132184 KB Output is correct
42 Correct 132 ms 132184 KB Output is correct
43 Correct 131 ms 132184 KB Output is correct
44 Correct 121 ms 132184 KB Output is correct
45 Correct 134 ms 132184 KB Output is correct
46 Correct 120 ms 132184 KB Output is correct
47 Correct 141 ms 134592 KB Output is correct
48 Correct 115 ms 134592 KB Output is correct
49 Correct 114 ms 134592 KB Output is correct
50 Correct 113 ms 134592 KB Output is correct
51 Correct 148 ms 148116 KB Output is correct
52 Correct 155 ms 148272 KB Output is correct
53 Correct 119 ms 148272 KB Output is correct
54 Correct 131 ms 148272 KB Output is correct
55 Correct 124 ms 148272 KB Output is correct
56 Correct 154 ms 148988 KB Output is correct
57 Correct 115 ms 148988 KB Output is correct
58 Execution timed out 1104 ms 262144 KB Time limit exceeded
59 Halted 0 ms 0 KB -