답안 #671134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671134 2022-12-12T07:06:24 Z NothingXD Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 61964 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
/*typedef __uint128_t L;
struct FastMod {
  ull b, m;
  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
  ull reduce(ull a) {
    ull q = (ull)((L(m) * a) >> 64);
    ull r = a - q * b; // can be proven that 0 <= r < 2*b
    return r >= b ? r - b : r;
  }
};
FastMod FM(2);*/
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 3e4 + 10;

int n, m, a[maxn], b[maxn];
map<pii,bool> mark;
map<pii,int> h;
vector<int> val[maxn];

void bfs(pii st){
	h[st] = 0;
	mark[st] = true;
	deque<pii> q;
	q.push_back(st);
	while(!q.empty()){
		int v = q.front().F, k = q.front().S;
		q.pop_front();
		for (auto x: val[v]){
			if (!mark[{v, x}] || h[{v, x}] > h[{v, k}]){
				h[{v, x}] = h[{v, k}];
				mark[{v, x}] = true;
				q.push_front({v, x});
			}
		}
		val[v].clear();
		if (v - k >= 0 && !mark[{v-k, k}]){
			h[{v-k, k}] = h[{v, k}] + 1;
			mark[{v-k, k}] = true;
			q.push_back({v-k, k});
		}
		if (v + k < n && !mark[{v+k, k}]){
			h[{v+k, k}] = h[{v, k}] + 1;
			mark[{v+k, k}] = true;
			q.push_back({v+k, k});
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n >> m;

	for (int i = 1; i <= m; i++){
		cin >> a[i] >> b[i];
		val[a[i]].push_back(b[i]);
	}

	bfs({a[1], b[1]});

	cout << (!mark[{a[2], b[2]}]? -1: h[{a[2], b[2]}]) << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 4 ms 1492 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 5 ms 1728 KB Output is correct
15 Correct 5 ms 1780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 4 ms 1492 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 5 ms 1748 KB Output is correct
15 Correct 5 ms 1748 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 14 ms 2876 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 5 ms 1748 KB Output is correct
24 Correct 11 ms 2644 KB Output is correct
25 Correct 6 ms 2004 KB Output is correct
26 Correct 6 ms 1948 KB Output is correct
27 Correct 5 ms 1876 KB Output is correct
28 Correct 18 ms 3892 KB Output is correct
29 Correct 59 ms 8684 KB Output is correct
30 Correct 13 ms 3144 KB Output is correct
31 Correct 27 ms 5148 KB Output is correct
32 Correct 18 ms 3884 KB Output is correct
33 Correct 151 ms 16040 KB Output is correct
34 Correct 157 ms 16048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 4 ms 1492 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 5 ms 1748 KB Output is correct
15 Correct 5 ms 1748 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 14 ms 2772 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 6 ms 1748 KB Output is correct
24 Correct 11 ms 2604 KB Output is correct
25 Correct 6 ms 1944 KB Output is correct
26 Correct 6 ms 2004 KB Output is correct
27 Correct 4 ms 1904 KB Output is correct
28 Correct 18 ms 3920 KB Output is correct
29 Correct 59 ms 8584 KB Output is correct
30 Correct 12 ms 3200 KB Output is correct
31 Correct 28 ms 5076 KB Output is correct
32 Correct 18 ms 3968 KB Output is correct
33 Correct 160 ms 15972 KB Output is correct
34 Correct 170 ms 15988 KB Output is correct
35 Correct 137 ms 14172 KB Output is correct
36 Correct 17 ms 3284 KB Output is correct
37 Correct 295 ms 22860 KB Output is correct
38 Correct 283 ms 21580 KB Output is correct
39 Correct 267 ms 21596 KB Output is correct
40 Correct 261 ms 21596 KB Output is correct
41 Correct 261 ms 21564 KB Output is correct
42 Correct 10 ms 2260 KB Output is correct
43 Correct 9 ms 2132 KB Output is correct
44 Correct 9 ms 1696 KB Output is correct
45 Correct 857 ms 61816 KB Output is correct
46 Correct 851 ms 61908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 5 ms 1492 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 5 ms 1748 KB Output is correct
15 Correct 5 ms 1780 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 15 ms 2776 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 5 ms 1748 KB Output is correct
24 Correct 11 ms 2612 KB Output is correct
25 Correct 6 ms 2004 KB Output is correct
26 Correct 6 ms 2004 KB Output is correct
27 Correct 5 ms 1876 KB Output is correct
28 Correct 18 ms 3924 KB Output is correct
29 Correct 64 ms 8784 KB Output is correct
30 Correct 13 ms 3112 KB Output is correct
31 Correct 27 ms 5088 KB Output is correct
32 Correct 19 ms 3924 KB Output is correct
33 Correct 150 ms 16024 KB Output is correct
34 Correct 154 ms 16012 KB Output is correct
35 Correct 140 ms 14140 KB Output is correct
36 Correct 17 ms 3304 KB Output is correct
37 Correct 303 ms 22860 KB Output is correct
38 Correct 266 ms 21592 KB Output is correct
39 Correct 267 ms 21684 KB Output is correct
40 Correct 258 ms 21576 KB Output is correct
41 Correct 253 ms 21608 KB Output is correct
42 Correct 10 ms 2260 KB Output is correct
43 Correct 9 ms 2176 KB Output is correct
44 Correct 9 ms 1696 KB Output is correct
45 Correct 848 ms 61768 KB Output is correct
46 Correct 857 ms 61964 KB Output is correct
47 Execution timed out 1054 ms 59760 KB Time limit exceeded
48 Halted 0 ms 0 KB -