Submission #243891

# Submission time Handle Problem Language Result Execution time Memory
243891 2020-07-02T05:13:14 Z Leonardo_Paes Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
396 ms 228468 KB
// same from Nson's code https://oj.uz/submission/243889
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;
#define f first
#define s second
const int maxn = 3e4+10, magic = 200, inf = 0x3f3f3f3f;
int b[maxn], p[maxn], dist1[maxn], dist2[maxn][magic+5];
vector<int> doges[maxn];
bool mark[maxn];
vector<pii> fila[maxn*magic];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> b[i] >> p[i];
        doges[b[i]].push_back(i);
    }
    memset(dist1, inf, sizeof dist1);
    memset(dist2, inf, sizeof dist2);
    fila[0].push_back({b[0], 0});
	for(int d = 0; !fila[d].empty(); d++) {
		while(!fila[d].empty()){
			int u = fila[d].back().f, id = fila[d].back().s;
			int power = p[id];
			fila[d].pop_back();
			if(power <= magic){
				if(dist2[u][power] == inf) dist2[u][power] = d;
				if(u + power < n and dist2[u + power][power] == inf){
					fila[d + 1].push_back({u + power, id});
					dist2[u + power][power] = d + 1;
				}
				if(u - power >= 0 and dist2[u - power][power] == inf){
					fila[d + 1].push_back({u - power, id});
					dist2[u - power][power] = d + 1;
				}
			}
			else{
				if(dist1[u] == inf) dist1[u] = d;
				if(!mark[id]){
					mark[id] = 1;
					for(int v=u+power, qtd=1; v<n; v+=power, qtd++) fila[d+qtd].push_back({v, id});
					for(int v=u-power, qtd=1; v>=0; v-=power, qtd++) fila[d+qtd].push_back({v, id});
				}
			}
			if(!doges[u].empty()){
				for(auto v : doges[u]) fila[d].push_back({u, v});
				doges[u].clear();
			}
		}
	}
    int ans = dist1[b[1]];
    for(int i=1; i<=magic; i++) ans = min(ans, dist2[b[1]][i]);
    cout << (ans == inf ? -1 : ans) << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 104 ms 166136 KB Output is correct
2 Correct 106 ms 166204 KB Output is correct
3 Correct 104 ms 166264 KB Output is correct
4 Correct 116 ms 166136 KB Output is correct
5 Correct 106 ms 166264 KB Output is correct
6 Correct 118 ms 166136 KB Output is correct
7 Correct 111 ms 166264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 166136 KB Output is correct
2 Correct 106 ms 166136 KB Output is correct
3 Correct 113 ms 166136 KB Output is correct
4 Correct 119 ms 166264 KB Output is correct
5 Correct 111 ms 166264 KB Output is correct
6 Correct 108 ms 166136 KB Output is correct
7 Correct 106 ms 166264 KB Output is correct
8 Correct 115 ms 166136 KB Output is correct
9 Correct 112 ms 166136 KB Output is correct
10 Correct 102 ms 166232 KB Output is correct
11 Correct 104 ms 166264 KB Output is correct
12 Correct 103 ms 166264 KB Output is correct
13 Correct 103 ms 166264 KB Output is correct
14 Correct 102 ms 166264 KB Output is correct
15 Correct 107 ms 166264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 166136 KB Output is correct
2 Correct 119 ms 166136 KB Output is correct
3 Correct 108 ms 166264 KB Output is correct
4 Correct 107 ms 166264 KB Output is correct
5 Correct 113 ms 166136 KB Output is correct
6 Correct 104 ms 166136 KB Output is correct
7 Correct 112 ms 166136 KB Output is correct
8 Correct 108 ms 166264 KB Output is correct
9 Correct 101 ms 166264 KB Output is correct
10 Correct 105 ms 166136 KB Output is correct
11 Correct 106 ms 166240 KB Output is correct
12 Correct 102 ms 166264 KB Output is correct
13 Correct 104 ms 166264 KB Output is correct
14 Correct 111 ms 166264 KB Output is correct
15 Correct 109 ms 166316 KB Output is correct
16 Correct 115 ms 166136 KB Output is correct
17 Correct 102 ms 166392 KB Output is correct
18 Correct 103 ms 166268 KB Output is correct
19 Correct 104 ms 166136 KB Output is correct
20 Correct 104 ms 166264 KB Output is correct
21 Correct 100 ms 166264 KB Output is correct
22 Correct 109 ms 166264 KB Output is correct
23 Correct 113 ms 166264 KB Output is correct
24 Correct 110 ms 166392 KB Output is correct
25 Correct 104 ms 166392 KB Output is correct
26 Correct 101 ms 166392 KB Output is correct
27 Correct 101 ms 166392 KB Output is correct
28 Correct 108 ms 166904 KB Output is correct
29 Correct 116 ms 166904 KB Output is correct
30 Correct 110 ms 166392 KB Output is correct
31 Correct 106 ms 166584 KB Output is correct
32 Correct 103 ms 166648 KB Output is correct
33 Correct 113 ms 167416 KB Output is correct
34 Correct 109 ms 167352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 166140 KB Output is correct
2 Correct 109 ms 166264 KB Output is correct
3 Correct 100 ms 166136 KB Output is correct
4 Correct 101 ms 166136 KB Output is correct
5 Correct 102 ms 166264 KB Output is correct
6 Correct 109 ms 166136 KB Output is correct
7 Correct 102 ms 166136 KB Output is correct
8 Correct 113 ms 166136 KB Output is correct
9 Correct 110 ms 166264 KB Output is correct
10 Correct 101 ms 166264 KB Output is correct
11 Correct 111 ms 166264 KB Output is correct
12 Correct 114 ms 166264 KB Output is correct
13 Correct 106 ms 166232 KB Output is correct
14 Correct 105 ms 166324 KB Output is correct
15 Correct 101 ms 166264 KB Output is correct
16 Correct 103 ms 166136 KB Output is correct
17 Correct 105 ms 166392 KB Output is correct
18 Correct 102 ms 166268 KB Output is correct
19 Correct 116 ms 166136 KB Output is correct
20 Correct 102 ms 166392 KB Output is correct
21 Correct 100 ms 166264 KB Output is correct
22 Correct 99 ms 166264 KB Output is correct
23 Correct 102 ms 166520 KB Output is correct
24 Correct 101 ms 166392 KB Output is correct
25 Correct 105 ms 166392 KB Output is correct
26 Correct 100 ms 166392 KB Output is correct
27 Correct 100 ms 166392 KB Output is correct
28 Correct 105 ms 167072 KB Output is correct
29 Correct 103 ms 166904 KB Output is correct
30 Correct 100 ms 166392 KB Output is correct
31 Correct 111 ms 166648 KB Output is correct
32 Correct 103 ms 166520 KB Output is correct
33 Correct 114 ms 167288 KB Output is correct
34 Correct 103 ms 167288 KB Output is correct
35 Correct 107 ms 167288 KB Output is correct
36 Correct 112 ms 166392 KB Output is correct
37 Correct 111 ms 167924 KB Output is correct
38 Correct 113 ms 167924 KB Output is correct
39 Correct 113 ms 167864 KB Output is correct
40 Correct 111 ms 167996 KB Output is correct
41 Correct 110 ms 167876 KB Output is correct
42 Correct 115 ms 167032 KB Output is correct
43 Correct 109 ms 167128 KB Output is correct
44 Correct 121 ms 167032 KB Output is correct
45 Correct 118 ms 170580 KB Output is correct
46 Correct 118 ms 170536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 166264 KB Output is correct
2 Correct 103 ms 166264 KB Output is correct
3 Correct 104 ms 166264 KB Output is correct
4 Correct 111 ms 166136 KB Output is correct
5 Correct 109 ms 166264 KB Output is correct
6 Correct 113 ms 166136 KB Output is correct
7 Correct 99 ms 166136 KB Output is correct
8 Correct 101 ms 166136 KB Output is correct
9 Correct 100 ms 166140 KB Output is correct
10 Correct 112 ms 166264 KB Output is correct
11 Correct 110 ms 166264 KB Output is correct
12 Correct 99 ms 166264 KB Output is correct
13 Correct 100 ms 166264 KB Output is correct
14 Correct 101 ms 166264 KB Output is correct
15 Correct 112 ms 166264 KB Output is correct
16 Correct 101 ms 166264 KB Output is correct
17 Correct 104 ms 166364 KB Output is correct
18 Correct 100 ms 166264 KB Output is correct
19 Correct 103 ms 166264 KB Output is correct
20 Correct 104 ms 166392 KB Output is correct
21 Correct 99 ms 166264 KB Output is correct
22 Correct 102 ms 166264 KB Output is correct
23 Correct 102 ms 166264 KB Output is correct
24 Correct 101 ms 166492 KB Output is correct
25 Correct 115 ms 166392 KB Output is correct
26 Correct 109 ms 166392 KB Output is correct
27 Correct 103 ms 166392 KB Output is correct
28 Correct 101 ms 166904 KB Output is correct
29 Correct 102 ms 166904 KB Output is correct
30 Correct 102 ms 166392 KB Output is correct
31 Correct 110 ms 166648 KB Output is correct
32 Correct 110 ms 166520 KB Output is correct
33 Correct 117 ms 167288 KB Output is correct
34 Correct 107 ms 167672 KB Output is correct
35 Correct 111 ms 167416 KB Output is correct
36 Correct 103 ms 166392 KB Output is correct
37 Correct 108 ms 167924 KB Output is correct
38 Correct 117 ms 168056 KB Output is correct
39 Correct 112 ms 167924 KB Output is correct
40 Correct 114 ms 167868 KB Output is correct
41 Correct 115 ms 167876 KB Output is correct
42 Correct 116 ms 167032 KB Output is correct
43 Correct 110 ms 167032 KB Output is correct
44 Correct 112 ms 167160 KB Output is correct
45 Correct 129 ms 170452 KB Output is correct
46 Correct 129 ms 170624 KB Output is correct
47 Correct 149 ms 173532 KB Output is correct
48 Correct 109 ms 167160 KB Output is correct
49 Correct 120 ms 166776 KB Output is correct
50 Correct 103 ms 166708 KB Output is correct
51 Correct 137 ms 170360 KB Output is correct
52 Correct 128 ms 170488 KB Output is correct
53 Correct 121 ms 168344 KB Output is correct
54 Correct 100 ms 166648 KB Output is correct
55 Correct 114 ms 166904 KB Output is correct
56 Correct 112 ms 168312 KB Output is correct
57 Correct 128 ms 171000 KB Output is correct
58 Correct 113 ms 168564 KB Output is correct
59 Correct 131 ms 169588 KB Output is correct
60 Correct 122 ms 169532 KB Output is correct
61 Correct 118 ms 169336 KB Output is correct
62 Correct 163 ms 181368 KB Output is correct
63 Correct 162 ms 187184 KB Output is correct
64 Correct 170 ms 191580 KB Output is correct
65 Correct 249 ms 202148 KB Output is correct
66 Correct 396 ms 228164 KB Output is correct
67 Correct 383 ms 228468 KB Output is correct