답안 #874544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874544 2023-11-17T08:13:38 Z arashMLG Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
286 ms 202580 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#endif
using namespace std;
 
typedef long long     ll;
typedef pair<int,int> pii;
 
const int N = 3e4 + 2;
const int M = 3e4+ 2;
const ll inf = 1e18;
 
#define F           first
#define S           second
#define pb          push_back
#define kill(x)     cout<<x<<endl, exit(0);
#define all(x)      x.begin(),x.end()
#define sz(x)       (int)x.size()
#define lc          (v << 1)
#define rc          ((v<<1) |1)
//#define int         long long

 
int n,m;
vector<int> here[N];
bool vis[N];
bitset<N> mark[M],mk[M];
deque<pair<pii,int>> dq;
//int dist[M][N];
int b[M],p[M];
int ans = -1;
 
void bfs() {
	mark[0][b[0]] = 1;
	dq.push_front({{0,b[0]},0});
	while(sz(dq)) {
		auto [sex,d] = dq.front(); dq.pop_front();
		auto [id,pos] = sex;
		//debug((int)id,(int)pos);
		assert(id >= 0 &&id < m);
		assert(pos >=0 && pos < n);
		if(id == 1) {
			kill(d);
		}
		mk[p[id]][b[id]] = 1;
		if(!vis[pos]) {
			for(int x : here[pos]) {
				if(!mark[x][pos]) {
					mark[x][pos] = 1;
					if(p[x] != p[id] || x == 1)
						dq.push_front({{x,pos},d});
				}
			}
			vis[pos] = true;
		}
		// front
		if(pos+ p[id] < n && !mark[id][pos + p[id]] && !mk[p[id]][pos + p[id]]) {
			mark[id][pos + p[id]] = true;
			mk[p[id]][pos + p[id]] = true;
			//dist[id][pos + p[id]] = dist[id][pos] + 1;
			dq.push_back({{id,pos+p[id]},d+1});
		}
		// back
		if(pos- p[id] >=0 && !mark[id][pos - p[id]] && !mk[p[id]][pos - p[id]]) {
			mark[id][pos - p[id]] = true;
			mk[p[id]][pos - p[id]]= true;
			//dist[id][pos - p[id]] = dist[id][pos] + 1;
			dq.push_back({{id,pos-p[id]},d+1});
		}
	}
}
 
int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n>>m;
	for(int i = 0 ; i <m; i++) {
		cin>>b[i]>>p[i];
		here[b[i]].pb(i);
	}
	bfs();
	kill(-1);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5212 KB Output is correct
4 Correct 1 ms 5208 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 5212 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5212 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 5208 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 1 ms 5208 KB Output is correct
10 Correct 1 ms 5468 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 5 ms 11868 KB Output is correct
13 Correct 4 ms 11868 KB Output is correct
14 Correct 4 ms 11868 KB Output is correct
15 Correct 4 ms 11868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5212 KB Output is correct
4 Correct 1 ms 5208 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 5212 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 1 ms 5468 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 4 ms 11868 KB Output is correct
13 Correct 4 ms 11868 KB Output is correct
14 Correct 4 ms 11868 KB Output is correct
15 Correct 4 ms 11868 KB Output is correct
16 Correct 1 ms 5212 KB Output is correct
17 Correct 4 ms 10332 KB Output is correct
18 Correct 2 ms 11356 KB Output is correct
19 Correct 2 ms 9308 KB Output is correct
20 Correct 4 ms 11864 KB Output is correct
21 Correct 2 ms 9308 KB Output is correct
22 Correct 1 ms 7260 KB Output is correct
23 Correct 3 ms 13916 KB Output is correct
24 Correct 5 ms 17244 KB Output is correct
25 Correct 3 ms 12524 KB Output is correct
26 Correct 1 ms 5212 KB Output is correct
27 Correct 5 ms 18196 KB Output is correct
28 Correct 5 ms 15960 KB Output is correct
29 Correct 3 ms 7256 KB Output is correct
30 Correct 1 ms 5348 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6236 KB Output is correct
33 Correct 6 ms 11868 KB Output is correct
34 Correct 5 ms 12084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5212 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5236 KB Output is correct
6 Correct 1 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 1 ms 5468 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 5 ms 11868 KB Output is correct
13 Correct 4 ms 12028 KB Output is correct
14 Correct 4 ms 11868 KB Output is correct
15 Correct 4 ms 11868 KB Output is correct
16 Correct 1 ms 5212 KB Output is correct
17 Correct 4 ms 10332 KB Output is correct
18 Correct 2 ms 11356 KB Output is correct
19 Correct 2 ms 9380 KB Output is correct
20 Correct 4 ms 12120 KB Output is correct
21 Correct 2 ms 9308 KB Output is correct
22 Correct 1 ms 7260 KB Output is correct
23 Correct 3 ms 13944 KB Output is correct
24 Correct 5 ms 17244 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 1 ms 5212 KB Output is correct
27 Correct 5 ms 18012 KB Output is correct
28 Correct 6 ms 16364 KB Output is correct
29 Correct 3 ms 7260 KB Output is correct
30 Correct 1 ms 5232 KB Output is correct
31 Correct 3 ms 6748 KB Output is correct
32 Correct 2 ms 6236 KB Output is correct
33 Correct 6 ms 11948 KB Output is correct
34 Correct 5 ms 11868 KB Output is correct
35 Correct 45 ms 105548 KB Output is correct
36 Correct 4 ms 16220 KB Output is correct
37 Correct 25 ms 57528 KB Output is correct
38 Correct 26 ms 59476 KB Output is correct
39 Correct 6 ms 12892 KB Output is correct
40 Correct 12 ms 25816 KB Output is correct
41 Correct 16 ms 35016 KB Output is correct
42 Correct 4 ms 5468 KB Output is correct
43 Correct 47 ms 121440 KB Output is correct
44 Correct 45 ms 115168 KB Output is correct
45 Correct 63 ms 115416 KB Output is correct
46 Correct 56 ms 115284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5212 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 5212 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 1 ms 5208 KB Output is correct
10 Correct 1 ms 5468 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 4 ms 11868 KB Output is correct
13 Correct 4 ms 11868 KB Output is correct
14 Correct 4 ms 11868 KB Output is correct
15 Correct 4 ms 11868 KB Output is correct
16 Correct 1 ms 5208 KB Output is correct
17 Correct 3 ms 10332 KB Output is correct
18 Correct 2 ms 11356 KB Output is correct
19 Correct 1 ms 9308 KB Output is correct
20 Correct 4 ms 11952 KB Output is correct
21 Correct 2 ms 9304 KB Output is correct
22 Correct 1 ms 7260 KB Output is correct
23 Correct 3 ms 13916 KB Output is correct
24 Correct 4 ms 17440 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 1 ms 5212 KB Output is correct
27 Correct 4 ms 18012 KB Output is correct
28 Correct 5 ms 15960 KB Output is correct
29 Correct 3 ms 7260 KB Output is correct
30 Correct 1 ms 5212 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 3 ms 6236 KB Output is correct
33 Correct 6 ms 11868 KB Output is correct
34 Correct 5 ms 11868 KB Output is correct
35 Correct 45 ms 105696 KB Output is correct
36 Correct 4 ms 16216 KB Output is correct
37 Correct 25 ms 57436 KB Output is correct
38 Correct 26 ms 59484 KB Output is correct
39 Correct 7 ms 12892 KB Output is correct
40 Correct 12 ms 25696 KB Output is correct
41 Correct 16 ms 34988 KB Output is correct
42 Correct 4 ms 5464 KB Output is correct
43 Correct 48 ms 121528 KB Output is correct
44 Correct 45 ms 115024 KB Output is correct
45 Correct 64 ms 115524 KB Output is correct
46 Correct 57 ms 115540 KB Output is correct
47 Correct 17 ms 31748 KB Output is correct
48 Correct 6 ms 11868 KB Output is correct
49 Correct 5 ms 9964 KB Output is correct
50 Correct 4 ms 7768 KB Output is correct
51 Correct 74 ms 194456 KB Output is correct
52 Correct 62 ms 202580 KB Output is correct
53 Correct 18 ms 44380 KB Output is correct
54 Correct 1 ms 5212 KB Output is correct
55 Correct 1 ms 5212 KB Output is correct
56 Correct 49 ms 102284 KB Output is correct
57 Correct 2 ms 5468 KB Output is correct
58 Correct 50 ms 115668 KB Output is correct
59 Correct 5 ms 5720 KB Output is correct
60 Correct 5 ms 5724 KB Output is correct
61 Correct 52 ms 177404 KB Output is correct
62 Correct 65 ms 143188 KB Output is correct
63 Correct 159 ms 117332 KB Output is correct
64 Correct 165 ms 115200 KB Output is correct
65 Correct 199 ms 115560 KB Output is correct
66 Correct 286 ms 115540 KB Output is correct
67 Correct 174 ms 115396 KB Output is correct