QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569937#9108. Zayin and ObstaclesSGColin#AC ✓356ms86904kbC++172.2kb2024-09-17 12:32:452024-09-17 12:32:45

Judging History

你现在查看的是最新测评结果

  • [2024-09-17 12:32:45]
  • 评测
  • 测评结果:AC
  • 用时:356ms
  • 内存:86904kb
  • [2024-09-17 12:32:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline ll rd() {
	ll x = 0;
	bool f = 0;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) f |= (c == '-');
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return f ? -x : x;
}

#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

const int N = 101;

int sum[N][N][N], id[N][N][N], dis[N * N * N];

vector<int> e[N * N * N];

const int dx[6] = {1, -1, 0, 0, 0, 0};
const int dy[6] = {0, 0, 1, -1, 0, 0};
const int dz[6] = {0, 0, 0, 0, 1, -1};

void work() {
	int n = rd(), m = rd();
	memset(sum, 0, sizeof(sum));
	int tot = 0;
	rep(i, 1, n) rep(j, 1, n) rep(k, 1, n) {
		id[i][j][k] = ++tot; e[tot].clear(); dis[tot] = 1e9;
	}
	rep(i, 1, m) {
		int a = rd(), b = rd(), c = rd();
		int d = rd(), e = rd(), f = rd();
		++sum[a][b][c];
		--sum[d + 1][b][c];
		--sum[a][e + 1][c];
		--sum[a][b][f + 1];
		++sum[d + 1][e + 1][c];
		++sum[d + 1][b][f + 1];
		++sum[a][e + 1][f + 1];
		--sum[d + 1][e + 1][f + 1];
	}
	rep(i, 1, n) rep(j, 1, n) rep(k, 1, n) {
		sum[i][j][k] += sum[i - 1][j - 1][k - 1] 
					  - sum[i][j - 1][k - 1]
					  - sum[i - 1][j][k - 1]
					  - sum[i - 1][j - 1][k]
					  + sum[i][j][k - 1]
					  + sum[i][j - 1][k]
					  + sum[i - 1][j][k];
		//printf("sum[%d][%d][%d] = %d\n", i, j, k, sum[i][j][k]);
	}
	rep(x, 1, n) rep(y, 1, n) rep(z, 1, n) if (!sum[x][y][z]) {
		rep(d, 0, 5) {
			int tx = x + dx[d];
			int ty = y + dy[d];
			int tz = z + dz[d];
			if (tx < 1 || tx > n || ty < 1 || ty > n || tz < 1 || tz > n) continue;
			if (sum[tx][ty][tz]) continue;
			e[id[x][y][z]].eb(id[tx][ty][tz]);
		}	
	}
	int x = rd(), y = rd(), z = rd();
	int s = id[x][y][z];
	x = rd(); y = rd(); z = rd();
	int t = id[x][y][z];
	dis[s] = 0;
	queue<int> q;
	q.push(s);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (auto v : e[u]) 
			if (dis[v] > dis[u] + 1) {
				dis[v] = dis[u] + 1;
				q.push(v);
			}
	}	
	printf("%d\n", dis[t] == 1e9 ? -1 : dis[t]);
}

int main() {
	per(t, rd(), 1) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 36184kb

input:

3
3 0
1 1 1 3 3 3
3 1
2 1 1 2 3 3
1 1 1 3 3 3
3 3
2 1 1 2 2 3
1 1 2 2 3 2
1 2 2 3 3 2
1 1 1 1 1 3

output:

6
-1
14

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 45ms
memory: 51812kb

input:

5
19 27
2 1 1 2 18 19
4 2 1 4 19 19
6 1 1 6 18 19
8 2 1 8 19 19
10 1 1 10 18 19
12 2 1 12 19 19
14 1 1 14 18 19
16 2 1 16 19 19
18 1 1 18 18 19
1 1 2 18 19 2
2 1 4 19 19 4
1 1 6 18 19 6
2 1 8 19 19 8
1 1 10 18 19 10
2 1 12 19 19 12
1 1 14 18 19 14
2 1 16 19 19 16
1 1 18 18 19 18
1 2 2 19 19 2
1 2 4 ...

output:

1998
15998
53998
127998
249998

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 94ms
memory: 47744kb

input:

5
99 147
2 1 1 2 98 99
4 2 1 4 99 99
6 1 1 6 98 99
8 2 1 8 99 99
10 1 1 10 98 99
12 2 1 12 99 99
14 1 1 14 98 99
16 2 1 16 99 99
18 1 1 18 98 99
20 2 1 20 99 99
22 1 1 22 98 99
24 2 1 24 99 99
26 1 1 26 98 99
28 2 1 28 99 99
30 1 1 30 98 99
32 2 1 32 99 99
34 1 1 34 98 99
36 2 1 36 99 99
38 1 1 38 9...

output:

132878
2596
227782
37198
90672

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 32ms
memory: 41328kb

input:

5
99 1000
2 1 1 2 98 99
4 2 1 4 99 99
6 1 1 6 98 99
8 2 1 8 99 99
10 1 1 10 98 99
12 2 1 12 99 99
14 1 1 14 98 99
16 2 1 16 99 99
18 1 1 18 98 99
20 2 1 20 99 99
22 1 1 22 98 99
24 2 1 24 99 99
26 1 1 26 98 99
28 2 1 28 99 99
30 1 1 30 98 99
32 2 1 32 99 99
34 1 1 34 98 99
36 2 1 36 99 99
38 1 1 38 ...

output:

4998
4998
4998
4998
4998

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 71ms
memory: 60036kb

input:

5
19 1000
2 1 1 2 18 19
4 2 1 4 19 19
6 1 1 6 18 19
8 2 1 8 19 19
10 1 1 10 18 19
12 2 1 12 19 19
14 1 1 14 18 19
16 2 1 16 19 19
18 1 1 18 18 19
4 13 10 4 19 12
6 5 5 6 6 18
6 16 4 6 18 11
8 6 10 8 17 19
14 10 7 14 17 12
2 4 4 2 5 15
4 5 10 4 7 17
12 1 2 12 2 9
12 8 10 12 18 15
16 19 2 16 19 8
8 1 ...

output:

-1
798
1906
3198
4998

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 356ms
memory: 86904kb

input:

5
100 0
92 81 37 11 85 14
100 0
16 48 91 61 65 58
100 0
87 25 52 83 7 45
100 0
80 95 16 62 5 80
100 0
33 33 50 48 82 3

output:

108
95
29
172
111

result:

ok 5 lines