Submission #47259

# Submission time Handle Problem Language Result Execution time Memory
47259 2018-04-29T18:37:48 Z yusufake Jakarta Skyscrapers (APIO15_skyscraper) C++
100 / 100
408 ms 210804 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;

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])
				Q[t+i].pb(mp(x+i*u,0));
			if(x - i*u >= 0 && !H[x-i*u][0])
				Q[t+i].pb(mp(x-i*u,0));
		}		
	}
	else if(!H[x][u]) 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 ; res < N*kok ; res++)
	for(i=0;i<Q[res].size();i++){
  	    x = Q[res][i].st;
		u = Q[res][i].nd;
//        cout << x << " " << u << " " << res << " ss\n";
		if(x == beg[1]) { cout << res; return 0; }
		if(H[x][u]) continue;
        H[x][u] = 1;
		if(u){ if(x+u<n && !H[x+u][u])Q[res+1].pb(mp(x+u,u)); if(x-u>=0 && !H[x-u][u])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++){
          ~^~~~~~~~~~~~~~
skyscraper.cpp:49:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<V[x].size();j++)
           ~^~~~~~~~~~~~
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 99 ms 125816 KB Output is correct
2 Correct 98 ms 125816 KB Output is correct
3 Correct 100 ms 125856 KB Output is correct
4 Correct 115 ms 125908 KB Output is correct
5 Correct 100 ms 125908 KB Output is correct
6 Correct 101 ms 125980 KB Output is correct
7 Correct 101 ms 125984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 125984 KB Output is correct
2 Correct 100 ms 125984 KB Output is correct
3 Correct 104 ms 126036 KB Output is correct
4 Correct 115 ms 126120 KB Output is correct
5 Correct 98 ms 126120 KB Output is correct
6 Correct 100 ms 126120 KB Output is correct
7 Correct 98 ms 126120 KB Output is correct
8 Correct 101 ms 126160 KB Output is correct
9 Correct 113 ms 126160 KB Output is correct
10 Correct 104 ms 126244 KB Output is correct
11 Correct 103 ms 126244 KB Output is correct
12 Correct 100 ms 126244 KB Output is correct
13 Correct 99 ms 126244 KB Output is correct
14 Correct 100 ms 126244 KB Output is correct
15 Correct 106 ms 126244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 126244 KB Output is correct
2 Correct 100 ms 126244 KB Output is correct
3 Correct 105 ms 126244 KB Output is correct
4 Correct 115 ms 126244 KB Output is correct
5 Correct 101 ms 126244 KB Output is correct
6 Correct 102 ms 126244 KB Output is correct
7 Correct 106 ms 126244 KB Output is correct
8 Correct 101 ms 126244 KB Output is correct
9 Correct 99 ms 126244 KB Output is correct
10 Correct 105 ms 126244 KB Output is correct
11 Correct 99 ms 126244 KB Output is correct
12 Correct 105 ms 126244 KB Output is correct
13 Correct 112 ms 126244 KB Output is correct
14 Correct 99 ms 126244 KB Output is correct
15 Correct 100 ms 126244 KB Output is correct
16 Correct 122 ms 126244 KB Output is correct
17 Correct 105 ms 126564 KB Output is correct
18 Correct 128 ms 126564 KB Output is correct
19 Correct 123 ms 126564 KB Output is correct
20 Correct 104 ms 127516 KB Output is correct
21 Correct 122 ms 127516 KB Output is correct
22 Correct 122 ms 127516 KB Output is correct
23 Correct 109 ms 127516 KB Output is correct
24 Correct 116 ms 127516 KB Output is correct
25 Correct 101 ms 127516 KB Output is correct
26 Correct 104 ms 127516 KB Output is correct
27 Correct 107 ms 127572 KB Output is correct
28 Correct 121 ms 128100 KB Output is correct
29 Correct 110 ms 128124 KB Output is correct
30 Correct 111 ms 128124 KB Output is correct
31 Correct 104 ms 128124 KB Output is correct
32 Correct 104 ms 128124 KB Output is correct
33 Correct 122 ms 128508 KB Output is correct
34 Correct 109 ms 128508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 128508 KB Output is correct
2 Correct 105 ms 128508 KB Output is correct
3 Correct 117 ms 128508 KB Output is correct
4 Correct 133 ms 128508 KB Output is correct
5 Correct 112 ms 128508 KB Output is correct
6 Correct 108 ms 128508 KB Output is correct
7 Correct 106 ms 128508 KB Output is correct
8 Correct 111 ms 128508 KB Output is correct
9 Correct 104 ms 128508 KB Output is correct
10 Correct 115 ms 128508 KB Output is correct
11 Correct 113 ms 128508 KB Output is correct
12 Correct 103 ms 128508 KB Output is correct
13 Correct 107 ms 128508 KB Output is correct
14 Correct 109 ms 128508 KB Output is correct
15 Correct 113 ms 128508 KB Output is correct
16 Correct 124 ms 128508 KB Output is correct
17 Correct 111 ms 128508 KB Output is correct
18 Correct 127 ms 128508 KB Output is correct
19 Correct 131 ms 128508 KB Output is correct
20 Correct 109 ms 128508 KB Output is correct
21 Correct 126 ms 128508 KB Output is correct
22 Correct 127 ms 128508 KB Output is correct
23 Correct 124 ms 128508 KB Output is correct
24 Correct 123 ms 128508 KB Output is correct
25 Correct 110 ms 128508 KB Output is correct
26 Correct 110 ms 128508 KB Output is correct
27 Correct 116 ms 128508 KB Output is correct
28 Correct 112 ms 128508 KB Output is correct
29 Correct 112 ms 128508 KB Output is correct
30 Correct 113 ms 128508 KB Output is correct
31 Correct 110 ms 128508 KB Output is correct
32 Correct 110 ms 128508 KB Output is correct
33 Correct 119 ms 128508 KB Output is correct
34 Correct 125 ms 128508 KB Output is correct
35 Correct 126 ms 128508 KB Output is correct
36 Correct 112 ms 128508 KB Output is correct
37 Correct 127 ms 128508 KB Output is correct
38 Correct 135 ms 128508 KB Output is correct
39 Correct 123 ms 128508 KB Output is correct
40 Correct 118 ms 128508 KB Output is correct
41 Correct 127 ms 128508 KB Output is correct
42 Correct 119 ms 128508 KB Output is correct
43 Correct 126 ms 128508 KB Output is correct
44 Correct 121 ms 128508 KB Output is correct
45 Correct 132 ms 132084 KB Output is correct
46 Correct 124 ms 132084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 132084 KB Output is correct
2 Correct 112 ms 132084 KB Output is correct
3 Correct 113 ms 132084 KB Output is correct
4 Correct 127 ms 132084 KB Output is correct
5 Correct 122 ms 132084 KB Output is correct
6 Correct 113 ms 132084 KB Output is correct
7 Correct 111 ms 132084 KB Output is correct
8 Correct 116 ms 132084 KB Output is correct
9 Correct 109 ms 132084 KB Output is correct
10 Correct 108 ms 132084 KB Output is correct
11 Correct 119 ms 132084 KB Output is correct
12 Correct 116 ms 132084 KB Output is correct
13 Correct 106 ms 132084 KB Output is correct
14 Correct 120 ms 132084 KB Output is correct
15 Correct 114 ms 132084 KB Output is correct
16 Correct 123 ms 132084 KB Output is correct
17 Correct 102 ms 132084 KB Output is correct
18 Correct 133 ms 132084 KB Output is correct
19 Correct 126 ms 132084 KB Output is correct
20 Correct 107 ms 132084 KB Output is correct
21 Correct 122 ms 132084 KB Output is correct
22 Correct 123 ms 132084 KB Output is correct
23 Correct 111 ms 132084 KB Output is correct
24 Correct 108 ms 132084 KB Output is correct
25 Correct 107 ms 132084 KB Output is correct
26 Correct 103 ms 132084 KB Output is correct
27 Correct 113 ms 132084 KB Output is correct
28 Correct 105 ms 132084 KB Output is correct
29 Correct 109 ms 132084 KB Output is correct
30 Correct 117 ms 132084 KB Output is correct
31 Correct 115 ms 132084 KB Output is correct
32 Correct 110 ms 132084 KB Output is correct
33 Correct 110 ms 132084 KB Output is correct
34 Correct 115 ms 132084 KB Output is correct
35 Correct 126 ms 132084 KB Output is correct
36 Correct 125 ms 132084 KB Output is correct
37 Correct 125 ms 132084 KB Output is correct
38 Correct 130 ms 132084 KB Output is correct
39 Correct 109 ms 132084 KB Output is correct
40 Correct 126 ms 132084 KB Output is correct
41 Correct 120 ms 132084 KB Output is correct
42 Correct 107 ms 132084 KB Output is correct
43 Correct 127 ms 132084 KB Output is correct
44 Correct 119 ms 132084 KB Output is correct
45 Correct 128 ms 132084 KB Output is correct
46 Correct 132 ms 132084 KB Output is correct
47 Correct 130 ms 134652 KB Output is correct
48 Correct 136 ms 134652 KB Output is correct
49 Correct 135 ms 134652 KB Output is correct
50 Correct 143 ms 134652 KB Output is correct
51 Correct 150 ms 148088 KB Output is correct
52 Correct 149 ms 148348 KB Output is correct
53 Correct 149 ms 148348 KB Output is correct
54 Correct 150 ms 148348 KB Output is correct
55 Correct 147 ms 148348 KB Output is correct
56 Correct 140 ms 148988 KB Output is correct
57 Correct 106 ms 148988 KB Output is correct
58 Correct 140 ms 149368 KB Output is correct
59 Correct 142 ms 149368 KB Output is correct
60 Correct 139 ms 149368 KB Output is correct
61 Correct 138 ms 149368 KB Output is correct
62 Correct 194 ms 156100 KB Output is correct
63 Correct 190 ms 158076 KB Output is correct
64 Correct 196 ms 159356 KB Output is correct
65 Correct 283 ms 177556 KB Output is correct
66 Correct 408 ms 210804 KB Output is correct
67 Correct 268 ms 210804 KB Output is correct