답안 #243889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243889 2020-07-02T04:52:17 Z Nson Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
428 ms 228748 KB
// modified from Leonardo_Paes's code https://pastebin.com/RUnXKRRp
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 166276 KB Output is correct
2 Correct 103 ms 166144 KB Output is correct
3 Correct 105 ms 166264 KB Output is correct
4 Correct 102 ms 166244 KB Output is correct
5 Correct 105 ms 166264 KB Output is correct
6 Correct 102 ms 166136 KB Output is correct
7 Correct 109 ms 166136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 166144 KB Output is correct
2 Correct 101 ms 166140 KB Output is correct
3 Correct 101 ms 166136 KB Output is correct
4 Correct 100 ms 166136 KB Output is correct
5 Correct 101 ms 166264 KB Output is correct
6 Correct 102 ms 166268 KB Output is correct
7 Correct 102 ms 166264 KB Output is correct
8 Correct 101 ms 166136 KB Output is correct
9 Correct 103 ms 166416 KB Output is correct
10 Correct 107 ms 166264 KB Output is correct
11 Correct 101 ms 166224 KB Output is correct
12 Correct 103 ms 166392 KB Output is correct
13 Correct 102 ms 166264 KB Output is correct
14 Correct 105 ms 166264 KB Output is correct
15 Correct 102 ms 166264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 166124 KB Output is correct
2 Correct 103 ms 166136 KB Output is correct
3 Correct 111 ms 166136 KB Output is correct
4 Correct 101 ms 166264 KB Output is correct
5 Correct 103 ms 166136 KB Output is correct
6 Correct 101 ms 166180 KB Output is correct
7 Correct 102 ms 166136 KB Output is correct
8 Correct 114 ms 166136 KB Output is correct
9 Correct 102 ms 166244 KB Output is correct
10 Correct 105 ms 166264 KB Output is correct
11 Correct 104 ms 166264 KB Output is correct
12 Correct 104 ms 166264 KB Output is correct
13 Correct 105 ms 166264 KB Output is correct
14 Correct 103 ms 166264 KB Output is correct
15 Correct 104 ms 166264 KB Output is correct
16 Correct 103 ms 166140 KB Output is correct
17 Correct 106 ms 166392 KB Output is correct
18 Correct 101 ms 166264 KB Output is correct
19 Correct 106 ms 166136 KB Output is correct
20 Correct 114 ms 166392 KB Output is correct
21 Correct 103 ms 166264 KB Output is correct
22 Correct 102 ms 166172 KB Output is correct
23 Correct 102 ms 166264 KB Output is correct
24 Correct 112 ms 166372 KB Output is correct
25 Correct 102 ms 166392 KB Output is correct
26 Correct 106 ms 166392 KB Output is correct
27 Correct 103 ms 166392 KB Output is correct
28 Correct 105 ms 166904 KB Output is correct
29 Correct 102 ms 166952 KB Output is correct
30 Correct 101 ms 166392 KB Output is correct
31 Correct 102 ms 166776 KB Output is correct
32 Correct 103 ms 166520 KB Output is correct
33 Correct 105 ms 167288 KB Output is correct
34 Correct 103 ms 167416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 166136 KB Output is correct
2 Correct 102 ms 166264 KB Output is correct
3 Correct 119 ms 166136 KB Output is correct
4 Correct 115 ms 166136 KB Output is correct
5 Correct 99 ms 166136 KB Output is correct
6 Correct 99 ms 166172 KB Output is correct
7 Correct 100 ms 166264 KB Output is correct
8 Correct 105 ms 166192 KB Output is correct
9 Correct 114 ms 166264 KB Output is correct
10 Correct 101 ms 166320 KB Output is correct
11 Correct 104 ms 166264 KB Output is correct
12 Correct 108 ms 166392 KB Output is correct
13 Correct 103 ms 166264 KB Output is correct
14 Correct 101 ms 166264 KB Output is correct
15 Correct 101 ms 166392 KB Output is correct
16 Correct 102 ms 166264 KB Output is correct
17 Correct 103 ms 166532 KB Output is correct
18 Correct 109 ms 166264 KB Output is correct
19 Correct 105 ms 166136 KB Output is correct
20 Correct 102 ms 166264 KB Output is correct
21 Correct 100 ms 166268 KB Output is correct
22 Correct 101 ms 166264 KB Output is correct
23 Correct 101 ms 166264 KB Output is correct
24 Correct 102 ms 166392 KB Output is correct
25 Correct 101 ms 166392 KB Output is correct
26 Correct 103 ms 166520 KB Output is correct
27 Correct 103 ms 166392 KB Output is correct
28 Correct 112 ms 166904 KB Output is correct
29 Correct 105 ms 166904 KB Output is correct
30 Correct 101 ms 166520 KB Output is correct
31 Correct 103 ms 166648 KB Output is correct
32 Correct 101 ms 166520 KB Output is correct
33 Correct 108 ms 167416 KB Output is correct
34 Correct 104 ms 167288 KB Output is correct
35 Correct 111 ms 167292 KB Output is correct
36 Correct 104 ms 166392 KB Output is correct
37 Correct 116 ms 167924 KB Output is correct
38 Correct 111 ms 167924 KB Output is correct
39 Correct 124 ms 167916 KB Output is correct
40 Correct 114 ms 167868 KB Output is correct
41 Correct 118 ms 167876 KB Output is correct
42 Correct 106 ms 167032 KB Output is correct
43 Correct 107 ms 167032 KB Output is correct
44 Correct 109 ms 167032 KB Output is correct
45 Correct 119 ms 170452 KB Output is correct
46 Correct 121 ms 170424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 166264 KB Output is correct
2 Correct 111 ms 166136 KB Output is correct
3 Correct 111 ms 166136 KB Output is correct
4 Correct 100 ms 166136 KB Output is correct
5 Correct 108 ms 166184 KB Output is correct
6 Correct 114 ms 166136 KB Output is correct
7 Correct 102 ms 166136 KB Output is correct
8 Correct 104 ms 166264 KB Output is correct
9 Correct 104 ms 166136 KB Output is correct
10 Correct 100 ms 166136 KB Output is correct
11 Correct 102 ms 166264 KB Output is correct
12 Correct 100 ms 166264 KB Output is correct
13 Correct 104 ms 166264 KB Output is correct
14 Correct 105 ms 166264 KB Output is correct
15 Correct 104 ms 166240 KB Output is correct
16 Correct 100 ms 166136 KB Output is correct
17 Correct 101 ms 166392 KB Output is correct
18 Correct 109 ms 166264 KB Output is correct
19 Correct 101 ms 166136 KB Output is correct
20 Correct 101 ms 166392 KB Output is correct
21 Correct 110 ms 166264 KB Output is correct
22 Correct 114 ms 166264 KB Output is correct
23 Correct 109 ms 166256 KB Output is correct
24 Correct 112 ms 166392 KB Output is correct
25 Correct 118 ms 166392 KB Output is correct
26 Correct 102 ms 166392 KB Output is correct
27 Correct 102 ms 166392 KB Output is correct
28 Correct 103 ms 166904 KB Output is correct
29 Correct 116 ms 166904 KB Output is correct
30 Correct 102 ms 166392 KB Output is correct
31 Correct 112 ms 166648 KB Output is correct
32 Correct 112 ms 166520 KB Output is correct
33 Correct 116 ms 167288 KB Output is correct
34 Correct 115 ms 167416 KB Output is correct
35 Correct 112 ms 167416 KB Output is correct
36 Correct 105 ms 166452 KB Output is correct
37 Correct 116 ms 167924 KB Output is correct
38 Correct 114 ms 167900 KB Output is correct
39 Correct 123 ms 167924 KB Output is correct
40 Correct 116 ms 167996 KB Output is correct
41 Correct 115 ms 168008 KB Output is correct
42 Correct 107 ms 167160 KB Output is correct
43 Correct 110 ms 167032 KB Output is correct
44 Correct 111 ms 167032 KB Output is correct
45 Correct 123 ms 170580 KB Output is correct
46 Correct 123 ms 170536 KB Output is correct
47 Correct 146 ms 173540 KB Output is correct
48 Correct 109 ms 166844 KB Output is correct
49 Correct 109 ms 166776 KB Output is correct
50 Correct 109 ms 166648 KB Output is correct
51 Correct 130 ms 170232 KB Output is correct
52 Correct 135 ms 170488 KB Output is correct
53 Correct 132 ms 168312 KB Output is correct
54 Correct 109 ms 166776 KB Output is correct
55 Correct 104 ms 166968 KB Output is correct
56 Correct 116 ms 168316 KB Output is correct
57 Correct 125 ms 171000 KB Output is correct
58 Correct 115 ms 168820 KB Output is correct
59 Correct 115 ms 169588 KB Output is correct
60 Correct 118 ms 169464 KB Output is correct
61 Correct 116 ms 169336 KB Output is correct
62 Correct 175 ms 181496 KB Output is correct
63 Correct 157 ms 187180 KB Output is correct
64 Correct 177 ms 191620 KB Output is correct
65 Correct 265 ms 202384 KB Output is correct
66 Correct 428 ms 228268 KB Output is correct
67 Correct 396 ms 228748 KB Output is correct